Crash when call CCSpriteFrameCache::addSpriteFramesWithFile

This method works fine in windows, but when I run my game on iOS simulator, it crashed.
After debug the program, I found when cocos2d-x using libxml to parse the plist file, it failed.
In the method:CCDictMaker::dictionaryWithContentsOfFile, when it called xmlSAXUserParseMemory,
this function return 4, not 0, which means something wrong. And CCDictMaker::dictionaryWithContentsOfFile return a null pointer.
Lately, cocos2d-x call a function on this null pointer, of course it will crashed.

So can anyone explain what’s wrong with it?

Did cocos2d-x team test it on iOS simulator?

I apologize for the crashes. There’re defects in .plist support, but we have just fixed them in the last week.

In the other hand, you can see the unit test source invoking CCSpriteFrameCache::addSpriteFramesWithFile in tests/tests/SpriteTest/SpriteTest.cpp. I can say responsible that we run this unit test well on all platfroms & all versions, including ios simulator.

The reasons of your crashes may be :
* .plist file is in binary format as default. #349 works for this, it’s just fixed yesterday.
* You use zwoptex osx version to generate .plist & png sheet. 0.8.1 only supports the output of zwoptex flash version. After #411 is done, we support the last zwoptex version on osx correctly.
And besides these 2, also #391 can cause the crash. Yep, it’s also fixed in the last week.

For avoid the crashes, you can get the edge version from github, or wait version#11 release in the next weekend.

Thanks for replay, I appreciate it.
I read the issue 411, my problem is exact same.
It cashed because the variable “dict” is null pointer, so “dict->objectForKey(string(”metadata“))” will receive a EXC_BAD_ACCESS signal.

I used TexturePacker free version to generate plist file, which is support cocos2d, and recommended by cocos2d-iphone official.
And I used cocos2d-x 0.8.1, this plist file can be parsed correctly on windows, it just can’t work on iOS simulator.I think this problem will be easy to be solved.
BTW, I will try to fix it by myself if possible, because my game will be published soon, I can’t wait for the next version of cocos2d-x. :slight_smile:

PS: Thanks for your guys great work. I love cocos2d-x.

I just write a test code based on the edge version, to check #411 #349 are both fixed. It works well. I will mail the project to you soon.
But I haven’t tried TexturePacker yet.

That’s very nice. Thank you.:slight_smile:

I am Andreas Loew - author of TexturePacker.
Do you still have problems here? Can I help you somehow?

@Andreas Loew
woa, great! I will download a trial version to check whether cocos2d-x compatible with TexturePacker

@Andreas Loew
Thanks, my problem has already solved.
BTW, TexturePacker is great.

@Walzer Wang:
You don’t need to use the trial version. Since you are a framework developer you and your team can get a free licenses. TexturePacker and PhysicsEditor.de are both free for framework developers and bloggers (with at least 5 non “hello world” posts which are related to development)

Dear All…

I Know this issue was 1 year ago, But I have some strange problem like this, So, please you nice people give me some help, please!

I use 0.13.beta now, and create my .plist by TexturePacker (Not trail version, I buy it two month ago) work on windows,
And everything is fine until I use cocos2d-x to load one .plise (Just this one, other is fine) and work on Android platform, It will crash
I test same project on iOS, it work fine,

My code just like below…

CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(“SpecEff.plist”);

@@….So…what should I do ??

By the way, Dear Andreas, the TexturePacker is useful, but It is some bug when I decrease the [Border padding] or [Inner Padding] <0, It will show error message and crash

I think the path is wrong.
As you know xcode can add folder in two ways.
What’s the path of “SpecEff.plist”? Is it under Resources/?

Minggo Zhang wrote:

I think the path is wrong.
As you know xcode can add folder in two ways.
What’s the path of “SpecEff.plist”? Is it under Resources/?

Thank you for response.

I think it’s some bug in parse trandition Chinese’’s png file name. I rename all the png filename to English and rebuild the .plist again.
And everything is going well now.

But if you need the error .plist & .png, I can offer for you to debug.

i also got a problem about this issue. here is the source code.

CCSpriteFrameCache * cache = CCSpriteFrameCache::sharedSpriteFrameCache();
int theme = 1;
char* filename = new char;
sprintf(filename, “map_theme.2d_back.plist”, them);
cache->addSpriteFramesWithFile(filename);

what’s wrong with this code? the map_theme.2d_back.plis is under the Resource folder

GuangHai Lin wrote:

i also got a problem about this issue. here is the source code.
>
CCSpriteFrameCache * cache = CCSpriteFrameCache::sharedSpriteFrameCache();
int theme = 1;
char* filename = new char;
sprintf(filename, “map_theme.2d_back.plist", them);
cache->addSpriteFramesWithFile(filename);

what’s wrong with this code? the map_theme.2d_back.plis is under the Resource folder
Did you try printing out what filename contains? Try this instead:
<pre>
int theme = 1;
CCSpriteFrameCache * cache = CCSpriteFrameCache::sharedSpriteFrameCache();
CCString * filename = CCString::createWithFormat(”map_theme_%02d_back.plist“, theme );
cache -> addSpriteFramesWithFile( filename -> getCString() );
</pre>
Above code will try to load the file named *map_theme_01_back.plist”

thanks a lot! my problem is solved. i just don’t understand what is wrong with my code? the filename is the same as yours, it equals “map_theme_01_back.plist”, why i can’t use the sprintf ?

GuangHai Lin wrote:

thanks a lot! my problem is solved. i just don’t understand what is wrong with my code? the filename is the same as yours, it equals “map_theme_01_back.plist”, why i can’t use the sprintf ?

I think you need to indicate the size of the char array for it to work.

int theme = 1;
char * filename = new char[ 128 ];
sprintf( filename, "map_theme_%02d_back.plist", theme );
CCSpriteFrameCache * cache = CCSpriteFrameCache::sharedSpriteFrameCache();
cache -> addSpriteFramesWithFile( filename );

thank you!