Frequent Save I/O issue

The engine is not working as expected? Documentation is wrong or out of date? Let us know here!
Forum rules
We are not providing support via this forum; it's community-driven. For official support see https://naninovel.com/support/#naninovel-support
Post Reply
zoelipg
Posts: 3
Joined: 26 Jan 2021 06:46

Frequent Save I/O issue

Post by zoelipg »

Hello! I'm frequently having an issue with saving the naninovel game state.

In my iOS app, I saved the state every second and continue saving another one if the previous save is successful. It works fine when saving 10-20 times, hard quit the app, and resuming the app to the right nanonovel position. BUT after playing the resumed game for first 10 times success saving, no matter I am using binary or json format for the save state, my code keeps stuck in lines:

Code: Select all

await IOUtils.WriteFileAsync(filePath, bytes);

for binary
or

Code: Select all

await IOUtils.WriteTextFileAsync(filePath, jsonData);

for json

It basically await at those lines forever.

I am in development build, it cannot reproduce on Unity Editor, but only on iOS device. Xcode does not throw any exception about this I/O corruption.
I check with iOS posts, seems they have open files limitation up to 200 files. But the Naninovel code seems always close the files?

Code: Select all

        public static async UniTask WriteFileAsync (string filePath, byte[] fileData)
        {
            if (Application.platform == RuntimePlatform.WebGLPlayer) File.WriteAllBytes(filePath, fileData);
            else
            {
                using (var fileStream = File.OpenWrite(filePath))
                    await fileStream.WriteAsync(fileData, 0, fileData.Length);
            }
            WebGLSyncFs();
        }

Any ideas for this I/O issues?

Elringus
admin
Posts: 521
Joined: 11 May 2020 18:03

Re: Frequent Save I/O issue

Post by Elringus »

Hi, Saving every second is definitely not a usual scenario and will cause performance issues. Given it's stuck on await fileStream.WriteAsync, the issue is most likely either with Unity's IO implementation of the API or on iOS side. I'd suggest not saving every second in the first place, but if you really want to do this, try switching to PlayerPrefs serialization handlers in the state configuration.

Post Reply