Losing data on iOS [SOLVED]

Easy Save 2 has been replaced by Easy Save 3, so is no longer supported.
Locked
Option4Studios
Posts: 4
Joined: Thu Apr 30, 2015 7:09 pm

Losing data on iOS [SOLVED]

Post by Option4Studios »

Hi Moodkie,

We think ES2 is fantastic. We’ve come across something curious which might be down to our programming and we’re not quite using ES2 correctly.

When we try out our game on a iOS device, we can manage to wipe the save data by quickly closing down the game (instead of suspending the game). In our code we are saving 15 pieces of data e.g

Code: Select all

lifeTime = ES2.Load<float>("rghsaves.txt?tag=lifeTimeSV");
We save on OnApplicationQuit() and OnApplicationPause().

Our theory was that the game was removed from memory quicker than ES2 could save, however that seems odd as the file is only 2kB! We haven’t replicated it on an Android device but it’s a slightly slower process to exit a game, which is maybe enough time to save.

So rather than being a ES2 issue, we thought perhaps we should be saving 2 save files. One for when you change scenes, pass a level, OnApplicationPause etc and the second for only OnApplicationQuit(). That way, there’s good chance if one file corrupts, the other may be up-to-date or slightly behind.

So our long winded question is have you heard of this issue and is our suggestion unnecessary and daft? :D

Kind regards

Richard@Option 4 Studios
Last edited by Option4Studios on Sun May 03, 2015 4:21 pm, edited 1 time in total.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Losing data on iOS

Post by Joel »

Hi Richard,

We've never heard of this before, and if this is indeed the case, it's a bug with Unity as it's specification says that those methods should be called in it's entirety when the application is quit. Easy Save is synchronous, so any code called in the method is completed before the method closes.

It might be a good idea to take a look at the log file using the instructions here to see if anything unusual is happening when you close the app. If you paste it here I'll take a look.

You may want to file a bug report with Unity regarding this. In the meantime, the best plan of action is to save two saves files (one as a backup) as you describe.

All the best,
Joel
Option4Studios
Posts: 4
Joined: Thu Apr 30, 2015 7:09 pm

Re: Losing data on iOS

Post by Option4Studios »

Thanks for the quick response Joel.

As no one else had mentioned it we wondered if we were being donuts, however I'm quite good at breaking things by rapidly selecting things in succession when testing. In this case it's the ipad/iphone home button and swiping off. So it's probably not a normal way of using an iOS device anyway.

It wouldn't surprise me if it was a Unity 5 bug though. We'll try and get a log to you by Monday at the latest or update the thread to say if we found anything else out/submitted a Unity bug report.

Kind regards

Richard
Option4Studios
Posts: 4
Joined: Thu Apr 30, 2015 7:09 pm

Re: Losing data on iOS

Post by Option4Studios »

We are still doing testing but an interesting set of results have already come in, where it might be related to this thread:

http://www.moodkie.com/forum/viewtopic.php?f=5&t=779

We received multiple 'Easy Save 2 Error: The data you are trying to load does not match the Load method you are using to load it.'

Also we save an index number in the save data as 1000001, and then incrementing on each save. Just before the save data disappears, that numbers changes to a random number like 68. The corruption of data also occurs on other saved variables. Very odd.

Anyhow, we'll keeping testing and see if we can create a skeleton project which replicates the behaviour.

FYI: We've been using Cloud build up to now but we will use our Mac hooked up to the iPad to get better debugging information.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Losing data on iOS

Post by Joel »

Does sound very similar to the BinaryWriter bug at Unity's end. Which version of Unity are you using? Does it only occur when using IL2CPP?

The bug first appeared in 4.6.3, but they then managed to integrate the same error into 5.0, so I wouldn't be surprised if they managed to reintroduce it again.

- Joel
Option4Studios
Posts: 4
Joined: Thu Apr 30, 2015 7:09 pm

Re: Losing data on iOS [Solved]

Post by Option4Studios »

Hi Joel,

That was it! While we are using 5.01f1 on our development machines, we didn't see the small detail that our Cloud Build project was set at 5.0.0f4. I thought I'd just check on the site, assuming it was building on the latest version. Never assume as they say.

We've set the Cloud build to 5.0.1p2 and it's solved the issue of lost/corrupt EasySave data.

Just a shame that we now have another weird issue occurring (not EasySave related) from that version of Unity...*sigh*

Thanks again for your quick responses. We shall post a 5* review for you.

Warm regards

Option 4 Studios
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Losing data on iOS [SOLVED]

Post by Joel »

Glad that solved your problem, let me know if you run into any other issues.

Hope you manage to get the other issues fixed with your project; Unity 5 can still be a bit temperamental, but we've found it's much quicker than 4 when it is working.

Thanks for the great review too, it's very much appreciated!

All the best,
Joel
Locked