Android cocos2d-x游戏在进入后台时崩溃

Android cocos2d-x游戏在进入后台时崩溃,android,iphone,cocos2d-iphone,cocos2d-x,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();

我的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)

应用程序委托方法
ApplicationIdentinterBackground:
在应用程序转换到后台后,但在应用程序挂起之前被调用。不幸的是,您可能无法在后台执行任何GPU指令,否则看门狗将终止您的操作(如您在此处所见)

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


无论您的代码是如何结构化的,在从
应用程序willresignactive:
委托调用返回之前,请确保动画循环已完全刷新并停止


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

我称之为ccdirector::sharedDirector()->stopAnimation()现在可以用了对不起,android现在崩溃了,ios是ok@OMGPOP我建议你问两个独立的问题,因为崩溃的原因肯定是不同的。我猜Android中会有另一个回调,你必须停止更新GPU,但你没有得到回调。“在从应用程序WillResignActive:delegate调用返回之前,确保动画循环已完全刷新并停止。”如何执行此操作?