"Positive number required" error at startup

Discussion and help for Easy Save 3
wilczarz
Posts: 7
Joined: Mon Mar 02, 2020 12:46 pm

"Positive number required" error at startup

Post by wilczarz »

Hi there,
I am using ES3 with encryption to store data in my ios game. It works fine when I build it manually on my mac, but when the app is built by Unity Cloud build, it fails like that:

Code: Select all

ArgumentOutOfRangeException: Positive number required.
Parameter name: bufferSize
  at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x00000] in <00000000000000000000000000000000>:0 
  at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean useAsync) [0x00000] in <00000000000000000000000000000000>:0 
  at ES3Internal.ES3Stream.CreateStream (ES3Settings settings, ES3Internal.ES3FileMode fileMode) [0x00000] in <00000000000000000000000000000000>:0 
  at ES3Writer.Create (ES3Settings settings, System.Boolean writeHeaderAndFooter, System.Boolean overwriteKeys, System.Boolean append) [0x00000] in <00000000000000000000000000000000>:0 
  at ES3.Save[T] (System.String key, System.Object value, ES3Settings settings) [0x00000] in <000<…>
This error happens when I set default values for the first time, so the files are probably being created at this moment.

I have found this thread describing similar problem:
https://moodkie.com/forum/viewtopic.php?f=13&t=1483

The advice was to remove Assembly-CSharp-firstpass from the Assemblies in the settings. Can someone explain to me why this is happening and why default settings won't work? I am only saving basic types, not using scene saving etc.
Thank you!

wilczarz
Posts: 7
Joined: Mon Mar 02, 2020 12:46 pm

Re: "Positive number required" error at startup

Post by wilczarz »

Hi again,

I have also found this topic suggesting that default settings prefab might be erased:
https://moodkie.com/forum/viewtopic.php?f=13&t=1596

But it seems ok:
Zrzut ekranu 2020-03-2 o 16.53.07.png
Zrzut ekranu 2020-03-2 o 16.53.07.png (136.17 KiB) Viewed 292 times
And this is moreless how I create the files (simplified version)

Code: Select all

private static readonly ES3Settings Settings = new ES3Settings(ES3.EncryptionType.AES, "some_complicated_password");

public static void SetDefaultValues()
{
if (!ES3.FileExists("debug.dat")) ES3.Save<bool>("data", false, "debug.dat", Settings);
if (!ES3.FileExists("sound.dat")) ES3.Save<bool>("data", false, "sound.dat", Settings);
// repeated for every file...
}
This code is called very early in the game - in Awake of the component that is at the top of script execution order list.

Can you help me please? My cloud builds are not working because of this :(

User avatar
Joel
Moodkie Staff
Posts: 2755
Joined: Wed Nov 07, 2012 10:32 pm

Re: "Positive number required" error at startup

Post by Joel »

Hi there,

Would you be able to run the following code in your iOS build immediately before calling your Save/Load code and let me know the output?
Debug.Log((new ES3Settings()).bufferSize)
Also would you be able to go to Edit > Project Settings > Player, and take a screenshot of the 'Other Settings' section?

It sounds like the settings are being corrupted upon build.

All the best,
Joel
Joel @ Moodkie Interactive
Twitter - Unity

wilczarz
Posts: 7
Joined: Mon Mar 02, 2020 12:46 pm

Re: "Positive number required" error at startup

Post by wilczarz »

Ok so this is the code and the output:

Code: Select all

Debug.Log("FOO: " + Settings.bufferSize + ", BAR: " + (new ES3Settings().bufferSize));
FOO: 0, BAR: 0
I also checked the same code built on local machine and the output is:

Code: Select all

FOO: 2048, BAR: 2048
And here is the screenshot of the player settings:
Settings.jpg
Settings.jpg (236.78 KiB) Viewed 280 times

User avatar
Joel
Moodkie Staff
Posts: 2755
Joined: Wed Nov 07, 2012 10:32 pm

Re: "Positive number required" error at startup

Post by Joel »

Hi there,

This would suggest that there is an error in Unity's build process which is resetting the bufferSize, so you might want to try updating to the latest stable version of Unity and file a bug report with them. I don't appear to be able to replicate this at my end, so I can't send a bug report myself.

You might also want to try deselecting String Engine Code in your build settings, and turn stripping off, to see if this is triggering the bug. If you can, also try reducing the API Compatibility Level to an earlier version.

All the best,
Joel
Joel @ Moodkie Interactive
Twitter - Unity

wilczarz
Posts: 7
Joined: Mon Mar 02, 2020 12:46 pm

Re: "Positive number required" error at startup

Post by wilczarz »

Hi Joel,

I wouldn't be so quick to blame Unity about it, and here is why: I have another project that uses Easy Save3 and it works just fine with Unity Cloud build. I looked into it and it turns out it has a bit older version of ES (late 2019 I suppose).
When I updated Easy Save in that project, it started to fail just the same. There must be some change in the recent updates of Easy Save that triggered this.

Also, I checked several versions of Unity in both projects and the behavior is consistent - older version of ES works and latest version fails. I can't find the version number in the older ES code. Would you like me to send it to you so that you can look into it?

Tom

User avatar
Joel
Moodkie Staff
Posts: 2755
Joined: Wed Nov 07, 2012 10:32 pm

Re: "Positive number required" error at startup

Post by Joel »

Hi Tom,

We've not changed the way that the default settings work since 2011, which is why I'm particularly sure it's an issue at Unity's end. It is simply a prefab which is loaded from Resources, so there's not really much that can go wrong at our end.

If you have time, would it be possible for you to try making a backup of the project which works, try updating Easy Save, and see if this triggers the issue? This will help narrow down the issue.

All the best,
Joel
Joel @ Moodkie Interactive
Twitter - Unity

wilczarz
Posts: 7
Joined: Mon Mar 02, 2020 12:46 pm

Re: "Positive number required" error at startup

Post by wilczarz »

Hi Joel,

That is exactly what I did. A project with a bit older version of EasySave is working fine, but when I update it from the asset store it breaks.
I can go back and forth between the versions of EasySave and I can confirm that one version is working and the other is not.

Do you think it may be because I am using EasySave very early in the app's lifetime and Resources folder is not working properly or something?
If you have any ideas where to go from here, I would appreciate it.

User avatar
Joel
Moodkie Staff
Posts: 2755
Joined: Wed Nov 07, 2012 10:32 pm

Re: "Positive number required" error at startup

Post by Joel »

Hi Tom,

It sounds like either Resources is failing to deserialise the script, or the values are not being written when the project is built. First thing, if you're building it using Unity Cloud I would try building it locally and see if this resolves the issue. I would also try deleting the Xcode project and see if regenerating it resolves the issue.

Firstly, to confirm that it's an issue at Unity's end, please could you run the following code and see what the output is:
Debug.Log(Resources.Load<GameObject>("ES3/ES3 Default Settings").GetComponent<ES3DefaultSettings>().bufferSize);
This loads the prefab directly from Resources, gets the ES3DefaultSettings Component and outputs the bufferSize. It is impossible to modify Resources after the application has been built, so if this doesn't return the value we see in the Editor then it must be a bug with Unity's build process.

Also another quick thing to check, though I think this would cause a compilation error, but if you're assembly definition files you might want to check that you've selected iOS as one of the platforms for that assembly definition file.

All the best,
Joel

All the best,
Joel
Joel @ Moodkie Interactive
Twitter - Unity

wilczarz
Posts: 7
Joined: Mon Mar 02, 2020 12:46 pm

Re: "Positive number required" error at startup

Post by wilczarz »

Hi Joel,

I started getting this bug in local builds as well (probably because I updated ES), so I finally discovered the problem.

You have recently modified method LoadDefaults in ES3Settings:
Zrzut ekranu 2020-03-5 o 10.17.20.png
Zrzut ekranu 2020-03-5 o 10.17.20.png (176.1 KiB) Viewed 256 times
As you can see, the settings are loaded from Resources only in the editor, whereas on actual device they are searched for in the scene. So I guess you did change it since 2011 after all ;-)
I don't like this new way, the editor and device use different configuration which is prone to errors in many ways.

Here is the two things I tried:
1) Adding the instance to the scene

This worked only for local builds. On cloud build this code:

Code: Select all

var settings = Resources.Load<GameObject>("ES3/ES3 Default Settings").GetComponent<ES3DefaultSettings>();
Debug.Log("FOO " + settings.settings.bufferSize + " " + (new ES3Settings()).bufferSize);
resulted in this:

Code: Select all

FOO 2048 0
2) Reverting the method to its previous state (no instance in the scene)
This fixed both builds like a charm

I'm not sure why Cloud Build behaves differently than my Mac, but at this point I am sure that the problem is in EasySave and not Unity.

Post Reply