After device suddenly shout down ,the userDefault.xml crash, nothing can be writen into it, any solutions ?


#1

Once after device suddenly shout down(power off) , enter the game again , I found the game data can’t be writen into the userDefault.xml.
I open the userDefault.xml ,only “<?xml version="1.0" encoding="utf-8"?>” existed, no parent node(userDefaultRoot), and the source code will return with nothing when there is no parent node.
So is there any solution except change the source code?


#2

sofa…


#3

Forgot one thing ,the version is 2.0.4


#4

You need to call CCUserDefault::flush() to persistent all datas in memory.
Please try to add @ CCUserDefault::sharedUserDefault()->flush(); @ into AppDelegate:applicationDidEnterBackground();


#5

Zhe Wang wrote:

You need to call CCUserDefault::flush() to persistent all datas in memory.
Please try to add @ CCUserDefault::sharedUserDefault()->flush(); @ into AppDelegate:applicationDidEnterBackground();

Well,it’s not the reason.
In version 2.0.4, I guess may be the libxml will clean the data before write new one, so when the device suddenly shut down before the data be writen will cause the userdefault.xml empty,
and the code can’t find the rootnode, then break,the game will never store data after the problem appears except going into the setting of the device and clean the data.

Now I use the 2.1.3, you drop the libxml and pick up the tinyxml,and store the data use sharedpreference(android),I tried to clean the data of the xml but not delete the xml,found it was ok,
can be writen again.But I’m not sure when I store many data often will slow down the speed(I tested in 2.0.4, i9100,very slow).Hope running well:) .