Cocos2d game crashes when loading many .plist at a time
My iphone game that I am currently working was developed using cocos2d
. The game crashes with the error:
Program received 0, Data Formatters, Debugging cannot continue......
After doing some research I've found out that it is running out of memory. I got the:
Received memory warning. Level=1 etc.
The source of the problem seems to be loading o开发者_运维知识库f plists files. It uses 4.0 MB just for loading about 23 .plist files to run different animations.
I would like to know how to load a bunch of plist files that runs different animations. The image is a screenshot of code that loads plist files along with its memory usage. I used instruments to get that result.
On further debugging here's what I got the assembler code
pop {r4, r5, r7, pc}
adds r0, #100 ; 0x64
lsls r3, r1, #0
--Error--
lsls r2, r1, #0
add r7, sp, #720
lsls r4, r1, #0
cbz r4, <0x7a>
lsls r4, r1, #0
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
//[[CCDirector sharedDirector] purgeCachedData];
}
Try commenting out purgeCachedData, and just call it when you exit your gameScene
For every call to addSpriteFramesWithFile
, Cocos2d loads the associated image file (.png), and you appear to have quite a lot of sprite sheets. I'm going to assume that each of these sheets is not huge, because obviously loading this many large textures would create memory warnings.
You should combine the smaller sprite sheets into one or more larger sprite sheets, as there is still a penalty for loading multiple textures, which internally will end up being padded to the next highest power of two dimensions. Not to mention the performance savings brought with less texture switching during drawing.
Also note that your change to applicationDidReceiveMemoryWarning
does not stop Cocos2d from removing textures, you need to comment out the call to removeAllTextures
as well in order to test that.
精彩评论