Save File Corruption

formerdc81

Chieftain
Joined
Nov 19, 2018
Messages
53
I made a mod that added one extra local variable to Player.cpp (a count for the number of free caravansaries not yet granted [because the player may have fewer cities than the specified number for free buildings] by my modded version of Legalism). I did my due diligence (or so I thought) and made it save and load this new variable. Ever since, I cannot load saved games because I get all sorts of bugs, even in parts of code I never touched like:
1) No matter what turn I load, as long as it is past 50 turns into the game and the starting era isn't Renaissance+, every nation founds a religion, breaking the hard-coded cap on religions. This then crashes the game not when the last civ finishes its turn, but when all the city-states (?) process their actions.
2) If I load from the beginning (before I found my first city) I get a screen that says 25/253,000 culture but 50 (!) free policies. (This was a test file for other features so I started in the medieval era. It should say 200/25, btw.) Building the Oracle freezes the game because I am forced to "adopt" a free policy before ending my turn but there is no more free policies left to adopt in the tree.
3) I reloaded it after I found my first city. It now says 200/25 culture like usual, but adopting policies does not increase the number beyond 25, meaning I once again quickly run out of policies to adopt.

I didn't modify the code related to policy costs and the game has no glitches if I just play it through without reloading, so I know it must be save corruption. Does anyone else also experience this problem?
 
Last edited:
If you mod the save/load code in the DLL without making the necessary checks, you can't load a save pre-changes. That is, you can't do save, change and recompile DLL, load new DLL, load old save.

If you're getting corruption from the sequence - change and recompile DLL, load new DLL, start a new game and save, load that save - it sounds like you've messed up the order of the read/write statements in the load/save methods
 
Back
Top Bottom