Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Netplay not synced when using start function #542

Open
1j01 opened this issue Aug 28, 2022 · 4 comments
Open

Netplay not synced when using start function #542

1j01 opened this issue Aug 28, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@1j01
Copy link

1j01 commented Aug 28, 2022

I was initializing my game inside the start callback, but this lead to a memory access error when trying to use netplay, or if I defined empty arrays at declaration like let players: Player[] = []; then the game would render but with entities missing on the client player's side. The host would see all the entities as well as inputs from the client player, but the client's game was broken.
I fixed it by moving initialization out of start and doing it at top level.
Is start just not supported yet for netplay?
This is a very cool feature, by the way! I love how simple you're trying to make it.

Here's my game for reference: https://github.com/1j01/polywogg
If you check out bcbf7aaa43 (before this workaround commit) you can see this issue.

@aduros
Copy link
Owner

aduros commented Aug 29, 2022

Hi, thanks a lot for reporting this!

I believe start shouldn't be called for joining clients, since calling it after joining would usually clobber the game state they just received from the host. There might actually be a bug causing start to be called when it shouldn't be.

@aduros
Copy link
Owner

aduros commented Aug 29, 2022

Cool game btw! I love Nidhogg.

@aduros aduros added the bug Something isn't working label Aug 30, 2022
CanyonTurtle pushed a commit to CanyonTurtle/PING that referenced this issue Apr 23, 2023
@CanyonTurtle
Copy link
Contributor

I ran into a desync issue and fixed it because of this thread. Thanks for documenting this!

My fix: CanyonTurtle/PING@a045f98#diff-d924ca21d81d7d5a59eb9e10d3e2689c4c58a7e28e6ecce6a064701666f5a730

My game:
https://canyonturtle.github.io/PING/

P.S. let me know what you think @aduros of the game! I'm not done with it yet but it's up there.

@JerwuQu
Copy link
Contributor

JerwuQu commented Apr 17, 2024

I built the game from the linked commit and the issue is clearly present.
Here's the built cart.wasm + cart.wat for anyone else interested in taking a look.

To elimiate the case of start being called multiple times, I added some debug logging in the runtime, and at least that is not the issue here.

I checked a wasm2wat conversion of the WASM and there are 26 WASM globals which immediately raises red flags, but since moving init stuff from start into update fixes the issue, I don't see how that could actually affect anything.

I managed to break at the first update in the joining client and it looks like the globals are indeed different:
2024-04-17_21-38-02_Discord_RpdLcufGfX
Not entirely sure this is the issue because the workaround works, but I wouldn't rule it out...

Tricky! Would be nice to test again if we ever fix globals for netplay (is it even possible?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants