Page 1 of 1

[1.1.52] crc fails on reading production statistics in replay

Posted: Wed Jan 19, 2022 9:10 am
by Thiske
Modifying then control.lua file from a save to extract information, and then rewatching the replay causes the crc to desync.
The line that is causing the problem is

Code: Select all

game.players[1].force.item_production_statistics.input_counts[item]
Somehow reading this table (even though it is read-only) changes the crc.
As an attachment is the save in question and the original save. (The " - kopie" is the modified one)

Re: [1.1.52] crc fails on reading production statistics in replay

Posted: Wed Jan 19, 2022 9:30 am
by boskid
Thanks for the report, however i am not considering tampering with control.lua of a save file with a replay to be a bug report worthy if there are any issues happening due to script change. In this particular case the issue is that item_production_statistics internally is a "LazyCreatedStatistics" so trying to read LuaForce::item_production_statistics when statistics were not yet created will change game state and a crc difference will happen.

Re: [1.1.52] crc fails on reading production statistics in replay

Posted: Wed Jan 19, 2022 9:51 am
by Thiske
yeah but normally script changes are allowed for this reason. To collect data in the background. (this is at least what the wiki says). That's why I though it was bug report worhty. Is there any way to disable this crc check? Or to read production stats without changes the game state?

Re: [1.1.52] crc fails on reading production statistics in replay

Posted: Wed Jan 19, 2022 10:05 am
by boskid
script changes of replay are allowed but this is the grey area of "if it works, it works. If it does not work, we are not going to fix it [in most cases]". In order to not desync when all clients in MP are running same code they should produce the same outcome. Replay may be considered as a just another client in MP game which receives input actions not from the network but from a file. We are free to make any optimizations that are deterministic and thats what happens here: item production statistics are not stored or managed until there is anything consumed or crafted. In most cases biters are not crafting anything so enemy force does not need statistics. There are no bugs here: in MP environment, script running on all clients is expected to cause same effects and in this case it would create statistics on all game instances - all of our requirements for determinism are fulfilled. By introducing a script change in the area which changes the game state and requesting us to fix this you are basically trying to force a "this is unusual use case, please no longer do any optimizations because they will cause replay issues when i change a script" and script change is not a intended use case. Item statistics are included in the heuristic crc generator which helps catching early if a client in MP game is diverging from server, but the same mechanism is used by replay. This heuristic crc generator however is checking if statistics are present and if they are not it simply skips including them for a given force (does not force them to exists). This is why by checking item_production_statistics which changes game state you get a crc fail: all of sudden your game instance doing a replay sees there are statistics and computes different crc for a "player" force. You can delay accessing item_production_statistics to a point when you know they exist but there are no api reads to know if given statistics exist already.