File being replaced with 0's

Discussion and help for Easy Save 3
Post Reply
MisterMorrisGames
Posts: 1
Joined: Thu May 02, 2024 11:44 pm

File being replaced with 0's

Post by MisterMorrisGames »

Hey Moodkie team,

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);
    }
Attachments
Player-glob.txt
(400 Bytes) Downloaded 20 times
H0-2024-4-26-13-58-40.txt
(320.76 KiB) Downloaded 14 times
H0-2024-4-30-21-22-44.txt
(390.6 KiB) Downloaded 15 times
User avatar
Joel
Moodkie Staff
Posts: 4852
Joined: Wed Nov 07, 2012 10:32 pm

Re: File being replaced with 0's

Post by Joel »

Hi there,

The ES3File API was deprecated quite a long time ago and is only used internally, so we cannot provide support for it. You should instead use caching as described here to achieve what you're doing:

https://docs.moodkie.com/easy-save-3/es ... ng-caching

When a file is replaced with 0s it usually means that anti-virus software has blocked it between writes (and will be accompanied by an Sharing Violation IOException, though you won't see this as you're catching the exception). Although we don't have control over what external software does with files, generally we've found that using caching resolves this in most cases because it only performs a single write.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply