@codemattic: It doesn't crash anymore. But now GAME_HUD.png is missing. The area that should contain GAME_HUD.png just shows white. Any other suggestions?
Global Array?
(40 posts) (7 voices)-
Posted 2 years ago #
-
just the usual - make sure GAME_HUD.png is included in your project (the little checkmark is checked). Make sure its spelled right. Its possible theres a problem with the png, switch it with a png that you know loads ok.
Posted 2 years ago # -
@codemattic: Thanks for the suggestions but it still doesn't load the png when the sprite is called from GameScene. I tested the png and it works fine in other code blocks. I had the following code in the dealloc methods of all my scenes:
[[TextureMgr sharedTextureMgr] removeAllTextures];I had hope that removing that code in the dealloc methods would cause the png to render correctly however it still renders as white space. Any other suggestions?
Posted 2 years ago # -
@codemattic: The png that is rendered is completely white but retains the dimensions of the image it should display. It's seems like the content of the image is missing.
Posted 2 years ago # -
I changed the order of the Sprite calls in ApplicationDidFinishLaunching after I found a similar issue with the white boxes in this thread.
This is how I had the code originally:
game_hud = [[Sprite spriteWithFile:@"GAME_HUD.png"] retain]; UIWindow *window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; [window setUserInteractionEnabled:YES]; [[Director sharedDirector] setLandscape: YES]; [[Director sharedDirector] attachInWindow:window]; [window makeKeyAndVisible]; GameScene * gs = [GameScene node]; [[Director sharedDirector] runWithScene:gs];This is what I changed it to:
UIWindow *window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; [window setUserInteractionEnabled:YES]; [[Director sharedDirector] setLandscape: YES]; [[Director sharedDirector] attachInWindow:window]; [window makeKeyAndVisible]; GameScene * gs = [GameScene node]; [[Director sharedDirector] runWithScene:gs]; game_hud = [[Sprite spriteWithFile:@"GAME_HUD.png"] retain];After I moved game_hud to execute after everything in ApplicationDidFinishLaunching, the png renders correctly. However, once the game is over and the scene changes, the app crashes. I believe the sprite is not storing its png contents even though it's being retained in the AppDelegate. Any suggestions? I feel like I'm really close to solving this issue.
Posted 2 years ago # -
instead of:
[[TextureMgr sharedTextureMgr] removeAllTextures];
try:
[[TextureMgr sharedTextureMgr] removeUnusedTextures];
But the code you posted looks ok to me. Maybe a memory bug elsewhere?
Posted 2 years ago # -
@codemattic: Thank you for your continued support.
I can only come to the conclusion that the problem will be fixed if upgrade my cocos2d version from 0.7.3 to 0.9.0. Do you think this will solve the problem? I'm hesitant to upgrade my code because I know there are a few changes in 0.9.0 that will mandate a complete overhaul of my code.
Posted 2 years ago # -
I remember 7.3 being pretty solid. I would not count on 9.x solving your problems. You *may* have a memory problem in your code somewhere and its not a bug in cocos.
When I find a bug Im almost always sure its a bug in cocos and not in my code - and Im almost always wrong ;)
As I said though - the code you posted looks ok to me. Good luck.
Posted 2 years ago # -
@codemattic: Thanks for pointing me in the right direction. I'll look over my code for memory leaks again. I'll post my findings as soon as I get it to work.
Posted 2 years ago # -
@codemattic: You were right. There were a couple of memory leaks in my code. The leaks were in the chipmunk physics code I created. Here is the offending code:
body = cpBodyNew(1.0f, cpMomentForPoly(1.0f, num, verts, cpvzero)); body->p = cpv(x, y); cpSpaceAddBody(space, body); shape = cpCircleShapeNew(body, radius, cpvzero); shape->e = 0.5f; shape->u = 0.0f; shape->data = answer_ball; cpSpaceAddShape(space, shape);The two lines that cause instruments to complain are:
body = cpBodyNew(1.0f, cpMomentForPoly(1.0f, num, verts, cpvzero)); shape = cpCircleShapeNew(body, radius, cpvzero);I've created code in my dealloc method like so:
cpBodyFree(body); cpShapeFree(shape);Adding cpBodyFree and cpShapeFree causes the code to crash. I have a feeling it's crashing because body and shape are global variables that I reinitialize multiple times in the game. How can I free this memory so my code no longer leaks? I'd be more than happy to share more code if it helps me solve this issue.
Posted 2 years ago #
Reply
You must log in to post.