Cocos2dx报OpenGL error 0x0506错误

近期做第三方sdk接入时,发现iOS8系统下,进行银联充值后,返回游戏有很大几率会报 
OpenGL error 0x0506............ 
之类的绘制问题,游戏卡死,花了很长时间,一直没有头绪 

最终找到这篇文章: 
http://blog.lessfun.com/blog/2014/09/24/ios8-issue-keyboard-orientation-and-idletimerdisabled-not-working/ 

原来后台运行的app,是不允许进行openGL绘制的,而且iOS8要求更严格 

好吧,切换到RootViewController.mm,加上这两个方法: 

Mix代码  收藏代码
  1. - (void)viewWillDisappear:(BOOL)animated  
  2. {  
  3.     [super viewWillDisappear:animated];  
  4.     cocos2d::CCApplication::sharedApplication()->applicationDidEnterBackground();  
  5. }  
  6.   
  7. - (void)viewWillAppear:(BOOL)animated  
  8. {  
  9.     [super viewWillAppear:animated];  
  10.     cocos2d::CCApplication::sharedApplication()->applicationWillEnterForeground();  
  11. }  



applicationDidEnterBackground主要是在切到后台时做这些: 

C++代码  收藏代码
  1. CCDirector::sharedDirector()->stopAnimation();  
  2. SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();  
  3. SimpleAudioEngine::sharedEngine()->pauseAllEffects();  



applicationWillEnterForeground是切回前台,做这些: 

C++代码  收藏代码
    1. CCDirector::sharedDirector()->startAnimation();  
    2. SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();  
    3. SimpleAudioEngine::sharedEngine()->resumeAllEffects();  
posted on 2016-07-11 16:46  许广  阅读(1063)  评论(0编辑  收藏  举报