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

OMG*_*POP 6 iphone android 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();
}
Run Code Online (Sandbox Code Playgroud)

和错误消息:

libGPUSupportMercury.dylib`gpus_ReturnNotPermittedKillClient:
0x3797e094:  trap   
0x3797e096:  nop    
Run Code Online (Sandbox Code Playgroud)

请注意,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)
Run Code Online (Sandbox Code Playgroud)

Jas*_*oco 5

该应用程序的委托方法applicationDidEnterBackground:被调用您的应用程序转换为背景,但之前你的申请被暂停.不幸的是,您可能无法在后台执行任何 GPU指令,或者监视程序将终止您(正如您在此处看到的那样).

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

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

注意:这个答案是为什么它总是在iOS上崩溃

  • “在从 applicationWillResignActive: 委托调用返回之前,请确保您的动画循环完全刷新并停止。” 怎么做? (2认同)