Cocos2d-x crashes when entering background

my cocos2d-x game crashes when entering the background. here is the code from AppDelegate:

// This function will be called when the app is inactive. When comes a phone call,it 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 error message:

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

Note that it always crashes for the iPhone, but 99% crashes on Android (well, when the game does not load large images, etc.)

EDIT: I tried CCDirector :: sharedDirector () -> stopAnimation () and it works great for iOS. But it still crashes for Android (not immediately.) When you return to the application, the screen turns black (but I think that it still works because the background music is still playing, and then after about 5 seconds it crashes)

EDIT 2: 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) 
+6
source share
1 answer

Application delegation method applicationDidEnterBackground: called after your application goes to the background, but before the application is paused. Unfortunately, you cannot execute any GPU instructions in the background, or the watchdog will end you (as you see here).

Assuming your call to CCDirector::sharedDirector()->pause() is responsible for stopping the graphics / animation cycle, you should transfer this to the applicationWillResignActive: delegate method. This method is called before your application goes to the background.

However, if you have structured code, make sure that the animation loop is completely cleared and stopped before you return from calling the applicationWillResignActive: delegate.

Note. This answer relates to why it always crashes on iOS

+5
source

Source: https://habr.com/ru/post/917929/


All Articles