cataclysmbnteam / Cataclysm-BN

Cataclysm: Bright Nights, A fork/variant of Cataclysm:DDA by CleverRaven.
https://docs.cataclysmbn.org
Other
620 stars 246 forks source link

Android save.json character reset bug #4444

Open RainaLute opened 2 months ago

RainaLute commented 2 months ago

Describe the bug

After opening the save it resets my character completely

Steps To Reproduce

1- Start the world 2- Spawn a bit far away from where you last save and quitted completely naked and lose off proffession

Screenshots

Screenshot_2024-04-06-13-57-17-749_com cataclysmbnteam cataclysmbn experimental

Versions and configuration

Additional context

[Uploading Cridersville.zip…]()

olanti-p commented 1 month ago

I'm not sure what's precisely going on here, but it seems that the game uses wrong parser function for reading the saved integer back from JSON. It saves a 64-bit integer, but tries to load it back as a 32-bit integer, so it doesn't fit and throws a parse error.

Uploading Cridersville.zip…

It seems you have submitted the issue form before waiting for the upload to finish (the text changes to file name once that happens).

olanti-p commented 1 month ago

On further thought, in code that number means count of references, which in theory should stay far, far, far below limits of 32-bit unsigned int. https://github.com/cataclysmbnteam/Cataclysm-BN/blob/5ab65d545fc76b3cbb8832bb4fbff922464a2949/src/safe_reference.cpp#L23-L26

But in the screenshot, it seems that the count has reached -1 for some reason, which caused overflow and had it appear as 2^32-1 = 4294967295, which got saved, and then promptly failed to be loaded. So the root of the issue is more likely somewhere inside reference tracking code.

olanti-p commented 1 month ago

For archival purposes, here's the save file from the issue: Cridersville.zip

And the problematic snippet:

  "safe_references": { "items": [ 11602, 4294967295 ] },

Another save file from same user: Boulder.zip

Different values this time - this doesn't even look like integer overflow, maybe memory corruption?

  "safe_references": { "items": [ 18446744073709551615, 2636248448, 11322597028362325620, 2636247792, 98784247841, 50559 ] },

As a note, those numbers don't repeat anywhere else in the save folder.