【问题标题】:cocos2d-x game crashes when entered backgroundcocos2d-x 游戏进入后台崩溃
【发布时间】:2012-06-13 04:15:17
【问题描述】:

我的 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 上崩溃,但 99% 在 Android 上崩溃(好吧,当游戏没有加载大图像等时)

编辑: 我已经尝试过 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)

【问题讨论】:

    标签: android iphone cocos2d-iphone cocos2d-x


    【解决方案1】:

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

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

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

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

    【讨论】:

    • 我调用了 ccdirector::sharedDirector()->stopAnimation(),它现在可以工作了
    • 抱歉,Android 现在崩溃了。 ios没问题
    • @OMGPOP 我建议您提出两个单独的问题,因为崩溃的原因肯定会有所不同。我的猜测是 Android 中还有另一个回调,您必须停止更新 GPU,但您没有收到回调。
    • "在您从 applicationWillResignActive: 委托调用返回之前,确保您的动画循环完全刷新并停止。"该怎么做?
    猜你喜欢
    • 2021-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-15
    相关资源
    最近更新 更多