在输入时的cocos2d-X游戏崩溃的背景 [英] cocos2d-x game crashes when entered background

查看:404
本文介绍了在输入时的cocos2d-X游戏崩溃的背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的cocos2d-X游戏进入后台时崩溃。这里是从AppDelegate中一些code:

  //当应用程序处于非活动状态,此功能将被调用。当谈到一个电话,它太调用
无效的AppDelegate :: applicationDidEnterBackground()
{    CCDirector :: sharedDirector() - >暂停();    CCUserDefault :: sharedUserDefault() - GT;的flush();    CocosDenshion :: SimpleAudioEngine :: sharedEngine() - > pauseBackgroundMusic();}//当应用程序被激活一次这个函数会被调用
无效的AppDelegate :: applicationWillEnterForeground()
{
    CCDirector :: sharedDirector() - GT;个人简历();    CocosDenshion :: SimpleAudioEngine :: sharedEngine() - > resumeBackgroundMusic();
}

和错误消息:

  libGPUSupportMercury.dylib`gpus_ReturnNotPermittedKillClient:
0x3797e094:陷阱
0x3797e096:NOP

请注意,它总是崩溃的iPhone,但是Android上99%的崩溃(好吧,当比赛还没有装载大图像等)

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

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

  libEGL调用的OpenGL ES API没有当前上下文(每个线程登录后)(红色警告文本)libc的致命信号11(SIGSEGV)在0x5f012000(code = 2)(黑色文本)


解决方案

应用程序的委托方法 applicationDidEnterBackground:被称为的之后的应用程序转换到背景,但是的的应用程序被暂停。不幸的是,你可能无法执行的任何的GPU的指令,而在后台,或看门狗将终止你(因为你看到这里)。

假设你的 CCDirector :: sharedDirector() - GT;暂停()调用负责回采图形/动画循环,你应该将那到 applicationWillResignActive:委托方法。这种方法被称为的的应用程序转移到后台。

然而,你有你的code结构,确保你的动画循环完全刷新和停止您从返回前applicationWillResignActive:委托电话

注:这个答案是在参考为何总崩溃在iOS

my cocos2d-x game crashes when entering background. here is some code from 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();
}

and the error message:

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

note that it always crashes for iPhone, but 99% crashes on Android (okay when the game haven't load large images etc)

EDIT: I've tried CCDirector::sharedDirector()->stopAnimation() and it works great for iOS. But still crashes for Android (not immediately. when returning back to the app, the screen become black (but i think it is still running because background music is still playing. then about 5 seconds later it crashes)

EDIT 2: The error message in 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)

解决方案

The app delegate method applicationDidEnterBackground: is called after your application transitions to the background, but before your application is suspended. Unfortunately, you may not perform any GPU instructions while in the background, or the watchdog will terminate you (as you're seeing here).

Assuming that your CCDirector::sharedDirector()->pause() call is responsible for stoping your graphics/animation loop, you should move that to the applicationWillResignActive: delegate method. That method is called before your application transitions to the background.

However you have your code structured, make sure your animation loop is completely flushed and stopped before you return from the applicationWillResignActive: delegate call.

Note: This answer is in reference to why it always crashes on iOS

这篇关于在输入时的cocos2d-X游戏崩溃的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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