[SOLVED] CCUserDefaults crashing when getting string

[SOLVED] CCUserDefaults crashing when getting string
0.0 0


So Im trying to save and load highscores using CCUserDefaults but whenever I try and use the getter function for a string the program crashes (win32).

This is what I am using to create the file if this is the first time the game is run:

CCUserDefault * saveFile = CCUserDefault::sharedUserDefault();
if(saveFile~~>getIntegerForKey ==1) //First time
CCLog(“Create SaveFile”);
for(int i = 0; i < 16; i++)
char nameBuffer[100];
sprintf(nameBuffer, “name%i”, i);
string str1 = “No Highscore”;
char scoreBuffer[100];
saveFile~~>setIntegerForKey(scoreBuffer, 0);

and this is what I am using to get the string and print it out:

char stringBuffer[100]; sprintf(stringBuffer, "name%i", (i*2)+q); string str2 = saveFile->getStringForKey(stringBuffer); CCLog("%s", str2);

and finally this is the output I get before the crash:

HEAP[HeroicHedgehog.win32.exe]: Invalid address specified to RtlValidateHeap( 02930000, 054E0F50 )
Windows has triggered a breakpoint in HeroicHedgehog.win32.exe.

This may be due to a corruption of the heap, which indicates a bug in HeroicHedgehog.win32.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while HeroicHedgehog.win32.exe has focus.

The output window may have more diagnostic information.

any help?


I think it is because the wrong usage of CCLOG(). The second parameter should be char*.


If I comment out the CCLog it still crashes :frowning:


Hi, Scott. We fixed bug #683 in v0.9.2. Are you still using v0.9.1?


I thought I was on 0.9.2 but apparently not. Update and now its working all fine :slight_smile: