cocos2d / cocos2d-x

Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
https://www.cocos.com/en/cocos2d-x
18.21k stars 7.06k forks source link

BlueTooth keyboard ON/OFF = Black screen with only fonts showing #10385

Open MFHSchoonbrood opened 9 years ago

MFHSchoonbrood commented 9 years ago

I'm testing on a nexus 7 with a bluetooth keyboard.

If I turn the keyboard on or off while a cocos app is running, the screen turns black and I only see font texts (tested with ttf and bitmap font).

What seems to happen is that the whole app is destroyed and recreated (judging by the message flow). Here is the relevant log:

D/MainActivity(11202): onPause
D/MainActivity(11202): onSaveInstanceState
I/native-activity(11202): AppDelegat=>applicationDidEnterBackground
D/MainActivity(11202): onStop
D/MainActivity(11202): onDestroy
D/JniHelper(11202): JniHelper::getJavaVM(), pthread_self() = 1726985600

D/MainActivity(11202): onCreate
D/dalvikvm(11202): Trying to load lib /data/app-lib/xxx.so 0x42574958
D/dalvikvm(11202): Shared lib '/data/app-lib/xxx.so' already loaded in same CL 0x42574958
D/main(11202): cocos_android_app_init
D/Cocos2dxActivity(11202): model=Nexus 7
D/Cocos2dxActivity(11202): product=nakasig
D/Cocos2dxActivity(11202): isEmulator=false
D/MainActivity(11202): onStart
D/MainActivity(11202): onResume
D/MainActivity(11202): ensureCocosHasFocus
I/native-activity(11202): AppDelegat=>applicationWillEnterForeground

First of all, it seems weird this happens at all... Why does the whole app need to be recreated, just because I turned on/off a bluetooth keyboard?

Second: All textures seem to be unloaded, so why is my bitmap font texture not unloaded? Is this by design or an oversight?

Third: How can I fix this? Is there a way in the code to detect that the textures have been unloaded, and reload them?

Kind regards, Michaël

MFHSchoonbrood commented 9 years ago

Here is the callstack when I break at the main activities onStop() function.

MyGame [Android Application]    
    DalvikVM[localhost:8600]    
        Thread [<1> main] (Suspended (breakpoint at line 126 in MyGame))    
            <VM does not provide monitor information>   
            MyGame.onStop() line: 126   
            Instrumentation.callActivityOnStop(Activity) line: 1212 
            MyGame(Activity).performStop() line: 5376   
            ActivityThread.performDestroyActivity(IBinder, boolean, int, boolean) line: 3442    
            ActivityThread.handleDestroyActivity(IBinder, boolean, int, boolean) line: 3501 
            ActivityThread.handleRelaunchActivity(ActivityThread$ActivityClientRecord) line: 3701   
            ActivityThread.access$900(ActivityThread, ActivityThread$ActivityClientRecord) line: 135    
            ActivityThread$H.handleMessage(Message) line: 1202  
            ActivityThread$H(Handler).dispatchMessage(Message) line: 102    
            Looper.loop() line: 136 
            ActivityThread.main(String[]) line: 5001    
            Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
            Method.invoke(Object, Object...) line: 515  
            ZygoteInit$MethodAndArgsCaller.run() line: 785  
            ZygoteInit.main(String[]) line: 601 
            NativeStart.main(String[]) line: not available [native method]