原文:http://discuss.cocos2d-x.org/t/BUG-in-cocos2dxrenderer-cpp/8619
I encountered a crash issue that,when you trIEd to install apk and start it from Eclipse,the game will surely crash with an assertion error if your phone’s screen is off. Here is the reason I found:
When the phone screen is off,androID will call onCreate,onResume,then onPause in order. While in onPause,Cocos2dxRenderer.nativeOnPause will be called. So see the code below:
JNIEXPORT voID JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnPause() {
CCApplication::sharedApplication()->applicationDIDEnterBackground();
CCNotificationCenter::sharednotificationCenter()->postNotification(EVENT_COME_TO_BACKGROUND,NulL);
}
Cocos2dxRenderer.nativeOnPause will attempt to call applicationDIDEnterBackground() of the current application. But it is NulL: because while the screen is off,androID won’t draw anything so that Cocos2dxRenderer.nativeInit isn’t called,and AppDelegate won’t be created.
But why the app don’t crash in onResume? I compared the native code of Cocos2dxRenderer.onResume:
JNIEXPORT voID JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnResume() {
if (CCDirector::sharedDirector()->getopenGLVIEw()) {
CCApplication::sharedApplication()->applicationWillEnterForeground();
}
}
I found a check before calling applicationWillEnterForeground(),this prevent calling applicationWillEnterForeground() while the application is not created.
I wonder why the implementation won’t check getopenGLVIEw() in onPause but in onResume only?
The issue above won’t effect much for the end-user,because they always launch your game with screen on. But it might lead to crash on some auto test system…
总结以上是内存溢出为你收集整理的cocos2dx onpause崩全部内容,希望文章能够帮你解决cocos2dx onpause崩所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)