I'm running into an issue where both save files and backups are being replaced with 0s whenever a player's computer shuts down unexpectedly, i.e. a power outage.
In the code, I save the player's progress using new ES3File(path) > do all the saving > then Sync(). After I wait for a few frames, check if the file can be loaded correctly (meaning it's not corrupted) and I make a backup using ES3.CreateBackup(path). If the file is corrupted/cannot be loaded then I skip making a backup - this is caught by the try/catch System.FormatException. I've tested it, and by this logic, corrupt backups should never be created.
What is strange is that both the normal save file AND the backup are being replaced with 0s whenever a player suddenly loses power so I don't think it has anything to do with how Easy Save 3 is handling the saving. Of course, I can't seem to replicate it on my machine which makes the issue harder to debug. However, with over 100,000 users, I have had numerous reports of this error, most of them due to the game crashing, power outages, or someone not closing the game and turning off the computer from the power button.
I'm wondering if there's anything else I'm missing such as not closing an open stream somewhere or something.
Attached is how a normal save file looks, and how a 'corrupt' file looks. Also, I've attached a second file for achievements 'player-glob.txt' which is sometimes harmed, and sometimes not. Maybe size has something to do with it?
Any help is appreciated as it's not a nice experience for players
Here is an example of the code for saving the game:
Code: Select all
void SaveGame()
{
//Turn on saving game screen
savingScreen.SetActive(true);
canClickSave = false;
savefile = new ES3File(PersistentFilePath.ins.currentFilePath);
//Save grid
GridSystem.ins.PrepareBuildingsAndCropsForSave();
savefile.Save("griddata", GridSystem.ins.tile);
SaveCropInventory();
SaveGameManagerInfo();
SaveBlockedLands();
SavePriorityOrder();
SaveFarmStatistics();
SaveTwitchBonusMoney();
//Sync save file
savefile.Sync();
//Backup savefile
StartCoroutine(CreateBackupIfNotCorrupted());
// turn off saving game screen
savingScreen.SetActive(false);
canClickSave = true;
}
Code: Select all
IEnumerator CreateBackupIfNotCorrupted()
{
yield return new WaitForSecondsRealtime(0.1f);
try
{
savefile = new ES3File(PersistentFilePath.ins.currentFilePath);
}
catch (System.FormatException)
{
yield break;
}
catch (System.IO.IOException)
{
yield break;
}
catch (System.UnauthorizedAccessException)
{
yield break;
}
ES3.CreateBackup(PersistentFilePath.ins.currentFilePath);
}