User Default getting corrupted in Windows

User Default getting corrupted in Windows
0.0 0

#1

Hello All, For last couple of days I am trying to get out the this problem but I didn’t get success.
There seems to a problem in fetching data from UserDefault on Windows. I am using cocos2dx 3.2.
Whenever I set Multiple value in user default using loop. User Default gets corrupted and after that I just get default Values of every Data type. And It gives “read root node error”
Here is the Code Snippet

for(int i= NUM_OF_HIGHEST_SCORES;i>=1;i–){
float savedScore = userDefault->getFloatForKey(String::createWithFormat("%s_%d_score",get_current_mode_key(currentGameMode),i)->getCString(),-1);
std::string savedName = userDefault->getStringForKey(String::createWithFormat("%s_%d_name",get_current_mode_key(currentGameMode),i)->getCString(),"");

        if((savedScore>currentValue || savedScore == -1)){
            rank    =   i;
            if(i==1){
                userDefault->setFloatForKey(String::createWithFormat("%s_%d_score",get_current_mode_key(currentGameMode),i)->getCString(),currentValue);
            }
            userDefault->setFloatForKey(String::createWithFormat("%s_%d_score",get_current_mode_key(currentGameMode),i+1)->getCString(),savedScore);
            userDefault->setStringForKey(String::createWithFormat("%s_%d_name",get_current_mode_key(currentGameMode),i+1)->getCString(),savedName.c_str());
        }else{
            userDefault->setFloatForKey(String::createWithFormat("%s_%d_score",get_current_mode_key(currentGameMode),i+1)->getCString(),currentValue);
            userDefault->setStringForKey(String::createWithFormat("%s_%d_name",get_current_mode_key(currentGameMode),i+1)->getCString(),savedName.c_str());
            break;
        }
    }

userDefault->flush();


#3

cocos2d-x 3.16 issue is still here


#4

I’m having the same problem on cocos2d-x 3.16…