Mod ingteb 0.4.0. causes desync

Place to get help with not working mods / modding interface.
Post Reply
ixu
Fast Inserter
Fast Inserter
Posts: 105
Joined: Sun May 29, 2016 6:18 pm
Contact:

Mod ingteb 0.4.0. causes desync

Post by ixu »

Users of my mod complain about desync crashes
desync-report-2022-04-10_08-41-28.zip
(47.6 MiB) Downloaded 95 times
. Can you help me find the cause?
Mods: ingteb, ixuClock, ixuAutoSave, NoCheating, hardCrafting (Maintainer) and more
Desperately tried to implement redo :)

robot256
Filter Inserter
Filter Inserter
Posts: 594
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: Mod ingteb 0.4.0. causes desync

Post by robot256 »

You'll get better advice when the experts arrive. I can try and point you in the right direction. Mod desyncs are usually caused by changes to the Lua environment state that differ from one client to another based on user input. Local variables, and all global variables except for the table named "global", are not part of the save file and are not transmitted to clients when they join a server. But they *are* part of the game state checksum, so if the local variables in a client do not match what they are in the server, then a desync is triggered.

The thing to check for in your code is any place a local or non-local variable is defined outside of a function, where the contents of that variable can change over time or based on user input. Any dynamic variables not in the "global" table must be perfectly recreated, based on data in the "global" table, game prototypes, and mod settings, during the "Load" phase of the Control stage. (This can be done in both inline code outside of any functions, and code passed to the script.on_load() function.)

I only glanced at your code, but it looks like you use a class structure. If the classes themselves are not stored in the "global" table, and if they have both functions and variable data in them, you will need to make sure all the data is mirrored in, and restored from, the "global" table. (Because there is no "save" event, you must assume the game could be saved and reloaded after any tick.)

Hope this helps a bit! Desyncs are frustrating.

ixu
Fast Inserter
Fast Inserter
Posts: 105
Joined: Sun May 29, 2016 6:18 pm
Contact:

Re: Mod ingteb 0.4.0. causes desync

Post by ixu »

New desync-report
download/file.php?id=73665
Mods: ingteb, ixuClock, ixuAutoSave, NoCheating, hardCrafting (Maintainer) and more
Desperately tried to implement redo :)

ixu
Fast Inserter
Fast Inserter
Posts: 105
Joined: Sun May 29, 2016 6:18 pm
Contact:

Re: Mod ingteb 0.4.x. causes desync

Post by ixu »

Steps the reproduce:
- start a new game and connect
- right-click on the ingteb-button (
thumbnail.png
thumbnail.png (2.61 KiB) Viewed 1550 times
)
- leave the game
- reconnect
-> crash

Restart the sever
- reconnect
-> works
- leave the game
- reconnect
-> crash
Mods: ingteb, ixuClock, ixuAutoSave, NoCheating, hardCrafting (Maintainer) and more
Desperately tried to implement redo :)

ixu
Fast Inserter
Fast Inserter
Posts: 105
Joined: Sun May 29, 2016 6:18 pm
Contact:

Re: Mod ingteb 0.4.0. causes desync

Post by ixu »

Needless to say:
I checked recreating of data several times.
Something is done in on-load but most things are done in first tick after restore.
As I can see there is no information used except
- global table that contains only strings and numbers
- information that is taken from game-, script- and defines-table

Everything is located directly or indirectly in the table EventManager. This table is created each time the scripts are loaded.
The mod is meant to help with very heavy mods. Therefore, to react fast enough, a lot of caching takes place.
This is done almost exclusively with the core/ValueCache class. This is built into the property feature of my class service (core/class and core/classclass) and is activated during property definition using cache = true.
I hope it can be done that way.
Mods: ingteb, ixuClock, ixuAutoSave, NoCheating, hardCrafting (Maintainer) and more
Desperately tried to implement redo :)

robot256
Filter Inserter
Filter Inserter
Posts: 594
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: Mod ingteb 0.4.0. causes desync

Post by robot256 »

I think doing things on the first tick after restore is the potential issue. According to the devs, code outside of on_load should never be aware that a save or load event has taken place. If the client is doing something "special" to restore a state during that tick and the server is not, and the game happens to compute a checksum on that tick, then it will detect the desync.

I think you will have to move all of the caching of things in EventManager into on_load. One way you could speed it up is by caching the prototype data in global, and only updating that cache in on_init and on_configuration_changed.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13177
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Mod ingteb 0.4.0. causes desync

Post by Rseding91 »

The 2 roots of all desyncs are:

1. using on_load wrong
2. using conditional event subscription wrong

The "easy" fixes are:

1. If you can delete on_load from your mod; do it.
2. If you are un-subscribing from event handlers; don't.

Simply store all your data in the 'global' table and react to events as they happen and you won't desync.

on_load is not required and conditional events are not required; both are a optimization that can be done if the mod author knows what they're doing. But, they're also easy to do wrong if the mod author doesn't know what they're doing.
If you want to get ahold of me I'm almost always on Discord.

ixu
Fast Inserter
Fast Inserter
Posts: 105
Joined: Sun May 29, 2016 6:18 pm
Contact:

Re: Mod ingteb 0.4.0. causes desync

Post by ixu »

Thank you so far.
By use of heavy mode I probably found some cause: I use the old flib.translate and I do not store the resulting translations in global table.
If you can delete on_load from your mod; do it.
When I just set metatables for some global objects that should be ok, shouldn't it.
Mods: ingteb, ixuClock, ixuAutoSave, NoCheating, hardCrafting (Maintainer) and more
Desperately tried to implement redo :)

ixu
Fast Inserter
Fast Inserter
Posts: 105
Joined: Sun May 29, 2016 6:18 pm
Contact:

Re: Mod ingteb 0.4.0. causes desync

Post by ixu »

Most of the time I get desync logs like this
desync.PNG
desync.PNG (188.69 KiB) Viewed 1436 times
And this is the only difference.
What could be the cause?
Mods: ingteb, ixuClock, ixuAutoSave, NoCheating, hardCrafting (Maintainer) and more
Desperately tried to implement redo :)

Post Reply

Return to “Modding help”