Oarcinae / FactorioScenarioMultiplayerSpawn

A custom scenario for Factorio which provides each player a unique starting spawn point in a multiplayer game.
MIT License
49 stars 30 forks source link

Desync with stored shared energy #136

Open ArchieBeepBoop opened 2 years ago

ArchieBeepBoop commented 2 years ago

It seems there's an occasional desync when the stored energy numbers are relatively large.

This seems to be due to the stored energy values being float points. (At least they look like floats) Perhaps because the numbers are growing a little bit too large, float loses precision and causes a desync.

I've used Hornwitser's factorio tools to identify the differences between the synchronized and desynchronized files and these are the results:

https://pastebin.com/cGiD1kEy

Oarcinae commented 2 years ago

Thanks for the report! That is definitely interesting... It's been awhile since I've looked into the code at all. Any suggestions for a possible fix based on what you found? I guess I could cap the max or something, but not sure if this means it is something I'm doing wrong or a bug in the game itself.

ArchieBeepBoop commented 2 years ago

I suppose a cap would be appropriate, yeah. Otherwise a different approach such as rounding the value and sending the value as an integer to clients could possibly help, but I'm not quite sure how lua treats floating point. Regardless, keeping that value uncapped does present the possibility of an overflow, which is also a source of desyncs as far as I know.