Desync, unraveling the mysteries

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
Sebastiaan
Engineer
Engineer
Posts: 110
Joined: 20 Jun 2005 19:22
Location: Leuven, Belgium

Desync, unraveling the mysteries

Post by Sebastiaan »

I'm trying to understand the mysteries (causes) of desync errors that appear due to code which has no effect on network or game variables whatsoever. (In casu: my statistics patch to which you find a link in my sig)

I did a small test and didn't find an answer but a lot of questions... :roll:

TEST SETUP:
- a non-patched version of the latest SVN trunk r5286 atm
- a patched version of the same trunk rev.

So far I tried a setup with the patched version as a server (the configuration in which i would like to use it later on) and joining the server with both non-patched and patched version.

Results can be summarized as follows: as soon as any train leaves the first station ever built (the train is on full load, after loading it turns, blows out smoke and makes an infinetesimal move) the game desyncs, both with a patched and a non-patched version.

The effect has been reproduced several times, with joining players being spectator, player in another company and, as said, of both versions. Curiously enough, no desyncs happen with depots, or other stations. switching the train in case did not resolve the problem, so i suspect the station. I attached the savegame for those who would like to reproduce it themselves (r5286)

QUESTIONS:
1) is it correct to state that a desync happens when the client is on a lower _frame_counter (== running behind?) AND the server changed that random feed in the meantime?
2) If i trace back changes in that _sync_seed_1, i end up with the function Random (misc.c) which changes the _random_seed. Further backtracing learns that is called, amongst others, by ChimneySmokeInit (vehicle.c). This looks like it could have to do with the problem in the savegame, but this function itself looks like it is never called at all. correct? And why is it in there?
3) following another route leads to OnNewDay_Train and then to CheckVehicleBreakdown (vehicle.c), which seems to use a random to determine if a train should suffer a breakdown. Unfortunately, this function too seems never to be called from anywhere.
4) The last function which seems to have anything to do with a train leaving the station, and which calls Random() is VehicleRandomBits, called by AddArticulatedParts which is only called in case of building new train-vehicles. That does not seem to be relevant.

5) What am I missing???
Attachments
DesyncTest.sav
(24.7 KiB) Downloaded 192 times
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Post by TrueBrain »

Really the easiest thing is to ask such questions on IRC. Then someone can answer you while you ask questions. But okay, let me try to explain some things.

Desyncs happen, and this is the only reason it can happen, when a client does a random and a server not, or the other way around. In order to keep a game in sync, in 1 frame the server and client need to do the same things, but most important: the same amount of Randoms. When this fails, a desyncs happen (in fact, it is that seeds are the only thing we can check).
In the game are all kind of protections to avoid this problem. One thing that can't be protected, is if the server calls more Randoms then a client does for an action. I suspect that your patch does a Random when a train leaves, and so you get a desync. Easy as pie ;)

About the other questions: I am pretty sure the function you mention are called. Just maybe not how you suspect. You should search for the functions, it would be there.

Anyway, I hope this helps you a bit. Contact me, or any of the other helpful people, on IRC if you have any more questions.

(ps: if you had searched the forum, you would have found some topics about this exact issue ;))
Sebastiaan
Engineer
Engineer
Posts: 110
Joined: 20 Jun 2005 19:22
Location: Leuven, Belgium

Post by Sebastiaan »

Solved. Thanks Truelight!
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 6 guests