File saved with full of zeros

Discussion and help for Easy Save 3
Post Reply
HoshinoArika
Posts: 5
Joined: Mon Aug 14, 2023 2:30 pm

File saved with full of zeros

Post by HoshinoArika »

I received reports from players that their save file is corrupted, and I found one of the save file is full of zeros instead of normal json format.
There are currently two save slots, one is normal and one is auto save, the auto save appears to be fine.
The attached zip file contains the save file with all zeros and the auto save file that is normal.

The code related to saving is

Code: Select all

private async UniTask SaveWorldAsync(bool useAutoSave = false)
    {
        this.Log($"SaveWorldAsync".ColorRed(), "Start Saving", $"IsAutoSave {useAutoSave}",
            "World Identifier: " + CurrentWorldIdentifier);

        if (!Global.code)
        {
            this.LogWarning("Not in Game Scene, returning");
            return;
        }

        var worldSaveFilePath = GetWorldSaveFilePath(useAutoSave);
        var es3Settings = new ES3Settings(worldSaveFilePath, ES3.Location.Cache);


        await SaveApplicationVersionAsync(es3Settings);
        await SaveEnemyAsync(es3Settings);
        await SaveEnviroTimeAsync(es3Settings);
        await SaveWeatherAsync(es3Settings);
        await SaveItemSpawnersAsync(es3Settings);
        await SaveFishSpawnersAsync(es3Settings);
        await SaveArmyAsync(es3Settings);
        await SaveSleepStateAsync(es3Settings);
        await SaveDestroyedObjectsAsync(es3Settings);
        await SaveLearnedItemsAsync(es3Settings);
        await SaveUnlockItemsAsync(es3Settings);
        await SaveDiscardItemsAsync(es3Settings);
        await SaveDropBagsAsync(es3Settings);
        await SaveCollectableAsync(es3Settings);
        await SaveRadioSystemAsync(es3Settings);
        await SaveLocationsAsync(es3Settings); 
        await SaveBuildingAsync(es3Settings);

        try
        {
            await Task.Run(() => { ES3.StoreCachedFile(worldSaveFilePath); });
        }
        catch (Exception e)
        {
            HandleException($"{LocalizedHints.SaveErrorHint}_{Application.version}", e.Message, e);
        }

        this.LogSuccess($"SaveWorldAsync".ColorRed(), "Finished Saving",
            "World Identifier: " + CurrentWorldIdentifier);
    }
Attachments
World.zip
(30.98 KiB) Downloaded 60 times
User avatar
Joel
Moodkie Staff
Posts: 4890
Joined: Wed Nov 07, 2012 10:32 pm

Re: File saved with full of zeros

Post by Joel »

Hi there,

This is usually always because an anti-virus has quarantined the file before a chance is given for the data to be written to it (usually this will also come with a Shared access exception). In this case the user would need to add an exception to their anti-virus for their file as you don't have control over what the anti-virus does as a developer.

However, in your case as you're using async code I would double check that you're only calling Easy Save from one thread at a time, as not doing so can cause a Shared access exception which will cause the above issue. I also recommend checking your error logs for exceptions.

In most cases it's not necessary to call StoreCachedFile asynchronously as it's usually quite a cheap operation unless you're saving things such as Textures or Meshes by value.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
HoshinoArika
Posts: 5
Joined: Mon Aug 14, 2023 2:30 pm

Re: File saved with full of zeros

Post by HoshinoArika »

Joel wrote: Sat Sep 23, 2023 6:50 am Hi there,

This is usually always because an anti-virus has quarantined the file before a chance is given for the data to be written to it (usually this will also come with a Shared access exception). In this case the user would need to add an exception to their anti-virus for their file as you don't have control over what the anti-virus does as a developer.

However, in your case as you're using async code I would double check that you're only calling Easy Save from one thread at a time, as not doing so can cause a Shared access exception which will cause the above issue. I also recommend checking your error logs for exceptions.

In most cases it's not necessary to call StoreCachedFile asynchronously as it's usually quite a cheap operation unless you're saving things such as Textures or Meshes by value.

All the best,
Joel
Thanks! I will inform my players and check my code again.
Post Reply