输入背景时cocos2d-x游戏崩溃

时间:2012-06-13 04:15:18

标签: android iphone cocos2d-iphone cocos2d-x

我的cocos2d-x游戏在进入后台时崩溃了。这是来自AppDelegate的一些代码:

// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground()
{

    CCDirector::sharedDirector()->pause();

    CCUserDefault::sharedUserDefault()->flush();

    CocosDenshion::SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();

}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
{


    CCDirector::sharedDirector()->resume();

    CocosDenshion::SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
}

和错误消息:

libGPUSupportMercury.dylib`gpus_ReturnNotPermittedKillClient:
0x3797e094:  trap   
0x3797e096:  nop    

请注意,iPhone总是崩溃,但Android上99%崩溃(当游戏没有加载大图片时等等)

编辑: 我已经尝试过CCDirector :: sharedDirector() - > stopAnimation(),它适用于iOS。但仍然崩溃的Android(不是立即。当返回到应用程序时,屏幕变黑(但我认为它仍在运行,因为背景音乐仍然在播放。然后大约5秒后它崩溃)

编辑2: Eclipse中的错误消息:

libEGL   call to OpenGL ES API with no current context (logged once per thread)      (red warning text)

libc     Fatal signal 11 (SIGSEGV) at 0x5f012000 (code=2)                  (black text)

1 个答案:

答案 0 :(得分:5)

应用程序委托方法applicationDidEnterBackground:在应用程序转换为后台后被称为,但应用程序暂停之前。不幸的是,您可能无法在后台执行任何 GPU指令,或者看门狗会终止您(正如您在此处看到的那样)。

假设您的CCDirector::sharedDirector()->pause()调用负责停止图形/动画循环,您应该将其移至applicationWillResignActive:委托方法。在应用程序转换为后台之前,该方法称为

但是,您的代码已经过结构化,请确保在从applicationWillResignActive:委托调用返回之前完全刷新并停止动画循环。

注意:这个答案是关于它总是在iOS上崩溃的原因