崩溃如果背景cocos2d 2.1应用程序在iOS7中观看游戏中心屏幕(排行榜,成就) [英] Crash if backgrounding cocos2d 2.1 app in iOS7 while watching Game Center screens (leaderboard, achievement)

查看:261
本文介绍了崩溃如果背景cocos2d 2.1应用程序在iOS7中观看游戏中心屏幕(排行榜,成就)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如果在iOS7中观看游戏中心屏幕(排行榜,成就)时使用cocos2d 2.1应用程式,可能会导致崩溃。



CCGLView.m中的第275行崩溃:

  if(![_ context presentRenderbuffer:GL_RENDERBUFFER])

,我下载了官方cocos2diphone 2.1的另一个新的副本,安装了它的模板和运行的主要应用程序挂钩到相同的应用程序ID,我的有问题的应用程序,已经有游戏中心排行榜等设置。它不会崩溃。所以我在lib中的cocos2d文件夹上运行diff,除了我在CCDrawingPrimitives.h / m中添加了一些C函数代码没有什么区别...应该不是问题。
所以问题不应该在cocos2d本身,但不知何故使用它或我的项目设置导致它。



更新:



问题似乎在于在2.1和更早版本中使用的cocos2d应用程序模板。它看起来像这样:

   - (void)applicationDidEnterBackground:(UIApplication *)application 
{
if ([navController_ visibleViewController] == director_)
[director_ stopAnimation];
}

这里显而易见的错误是,如果你有navController打开一个Game Center控制器,那么当按下主页按钮时,director_的visibleViewController将是GC控制器,因此stopAnimation将不会被调用。这会导致与iOS7崩溃,但似乎与iOS6 ...或模板cocos2d 2.1应用程序(仍然困惑这里)。



当前的修复是要注释掉 if([navController_ visibleViewController] == director_)以便总是调用stopAnimation。

解决方案

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



所以我的解决方案是停止导演动画显示游戏中心之前。 / 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!

这篇关于崩溃如果背景cocos2d 2.1应用程序在iOS7中观看游戏中心屏幕(排行榜,成就)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆