I have a 100% reproducible crash here.
Crash if backgrounding cocos2d 2.1 app in iOS7 while watching Game Center screens (leaderboard, achievement). It crashes instantly when pushing the home button.
Crash on line 275 in CCGLView.m:
if(![_context presentRenderbuffer:GL_RENDERBUFFER])
The itching thing is, I downloaded a fresh copy of official cocos2diphone 2.1 the other second, installed its templates and ran the staple application after hooking it up to the same app id as my problematic app that already have game center leaderboards etc set up. It does not crash. So I ran a diff on the cocos2d folders inside lib, and there is no difference except I added some C functions code in CCDrawingPrimitives.h/m... Should not be the problem. So the problem should not be in cocos2d itself but somehow the use of it or my project setup causes it.
Update:
The problem seems to be in the cocos2d app template in use in 2.1 and possibly earlier. It looks like this:
-(void) applicationDidEnterBackground:(UIApplication*)application
{
if( [navController_ visibleViewController] == director_ )
[director_ stopAnimation];
}
And the obvious fault here is that if you have navController open a Game Center controller, then when pushing the home button the visibleViewController of director_ will be the GC controller, hence the stopAnimation will not get called. This results in a crash with iOS7, but doesn't seem to with iOS6... nor the template cocos2d 2.1 app (still confused here).
The current fix is to comment out if( [navController_ visibleViewController] == director_ )
in order to have stopAnimation always called. Not sure if there are any side effects with that but will go with this for now.
Good Call. I ran into the same issue as you do and your post helped me to figure out how my app crashed.
So my solution is stop director animation before showing game center.
[[CCDirector sharedDirector] stopAnimation]
[[CCDirector sharedDirector] presentViewController:gcViewController animated:YES completion:nil];
Then restart animation in the game center view dismiss callback
- (void) gameCenterViewControllerDidFinish:(GKGameCenterViewController *)gameCenterViewController
{
[[CCDirector sharedDirector] dismissViewControllerAnimated:YES completion:nil];
[[CCDirector sharedDirector] startAnimation];
}
Your updated solution should work, but same here, I am not sure if there would be any side effects. I guess it is a safer approach to just wrap around the game center itself.
Thanks again for posting this question!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With