加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

cocos2dx onpause崩

发布时间:2020-12-14 19:57:49 所属栏目:百科 来源:网络整理
导读:原文: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 of

原文: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…

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读