thomaswp / BeaverBuddies

GNU General Public License v3.0
16 stars 2 forks source link

When the host lag, Client obtains desynchronization #33

Closed Cilyena closed 1 month ago

Cilyena commented 1 month ago

I'm using an empty 10x10 world for my test.

Host Lag 2 seconds and between these 2 seconds (between 10-57-55.56 & 10-57-57.04) S0 changed on the client side. This causes a desync.

Host :

image

Client :

image

Cilyena commented 1 month ago

I think that if the client is faster than the server, the client should pause.

Cilyena commented 1 month ago

I've tried to make changes, but it's far too complicated for me. The netcode causes a lot of desync during lags and GUIDs used during lags. I've also noticed that if you try to click several times to put a route in the same place (like 10 times in one second), it systematically causes a desync. I hadn't tested the mod in Update 5 of the game, but I think these problems were already present.

thomaswp commented 1 month ago

I've encountered this desync as well, though I can't reproduce it reliably. Have you been able to? If so, what do you do to create the server lag, specifically? I've tried, for example, tabbing out: the server pauses, but that doesn't cause the desync. Reproducing the issue would be very important, since I can't test it without knowing how to cause the bug reliably.

I think that if the client is faster than the server, the client should pause.

It is designed to do this. But I'll take another look to see how it might be ticking without receiving data from the server. The other possibility is that somehow the server is sending ticks early or incorrectly, making the client think it's further ahead than it is.

It's actually an interesting find that the client is ticking without changing the random seed - normally it would change every tick, since something random happens every tick without fail. That suggests that the ticks that are happening on the Client may not be normal game ticks...

thomaswp commented 1 month ago

More specifically, the client is set to pause if there are no ticks received from the host in the queue. So it is possible that something is causing the client to tick when pause (or unpausing it). I could definitely make a more explicit check to stop the client from ticking if there's no tick to replay from the host. However, it would be great to have a way to reproduce the bug to see if that's actually the issue.

thomaswp commented 1 month ago

Ok, I think I have a fix for it in v6 now (main code is here, though I fix some bugs in later commits: https://github.com/thomaswp/BeaverBuddies/commit/13d12fb5e602977deb7e08bc02f95a047007c68b)

If you can reliable create the desync from server lag, please let me know if this fixes it.

Cilyena commented 1 month ago

I set the speed to x99 and reduced the host priority with ProcessXP (tool to download). This greatly increases the probability of causing the problem. I won't be able to test for a couple of weeks, when I get home I'll test. Thanks for these fixes.

thomaswp commented 1 month ago

Ok, I was able to reproduce the issue (99x speed was a good call - I didn't think to use the dev console!), but with the new fix it's not causing a desync! I'll mark resolved for now, but please reopen if you're still getting it.