且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

崩溃如果背景cocos2d 2.1应用程序在iOS7中观看游戏中心屏幕(排行榜,成就)

更新时间:2022-12-25 18:29:01

好电话。我遇到了同样的问题,你做的和你的帖子帮助我弄清楚我的应用程序崩溃。



所以我的解决方案是停止导演动画显示游戏中心之前。 / p>

  [[CCDirector sharedDirector] stopAnimation] 
[[CCDirector sharedDirector] presentViewController:gcViewController animated:YES completion:nil];

然后在游戏中心重新开始动画视图dismiss callback

   - (void)gameCenterViewControllerDidFinish:(GKGameCenterViewController *)gameCenterViewController 
{
[CCDirector sharedDirector] dismissViewControllerAnimated:YES completion:nil];
[[CCDirector sharedDirector] startAnimation];
}

您更新的解决方案应该可以正常工作,将是任何副作用。我想这是一个更安全的方法,只是包装游戏中心本身。



再次感谢发布此问题!


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!