-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Description
- I tested it on latest raylib version from master branch
- I checked there is no similar issue already reported
- I checked the documentation on the wiki
- My code has no errors or misuse of raylib
Issue description
Whenever a configuration change happens (Orientation change, screen size change, a USB keyboard is plugged in, etc..) the Android OS has to destroy and recreate the activity from scratch. When using a NativeActivity with the glue code provided in the NDK, android_app.destroyRequested is set to 1.
The way raylib currently handles activity recreation is to ignore destroyRequested, which ends up with the app not responding due to the system sending PAUSE, STOP, and DESTROY commands. Raylib happily destroys the surface and GL context; however, the app thread is never terminated, which is what the system expects to happen so it can create the activity again.
One solution is to have the app opt to handle certain configuration changes itself and instruct the system not to recreate the activity by declaring certain values in the android:configChanges manifest attribute.
This approach works well for handling orientation changes, but it might not work for other config changes that are either not handled or just refuse to work (e.g. USB keyboard always recreates the activity even if keyboard is declared in android:configChanges).
The proper way to solve this is to correctly handle destroyRequested by letting android_main return to its caller and allowing the system to recreate the NativeActivity and call android_main again.
Of course, calling android_main more than once means raylib will have to reinitialize global state to 0 and somehow keep track of game data that needs to be restored by saving it to android_app.savedState when the SAVE_STATE command is issued.
Here's a small diff that fixes the hangs but doesn't do any game state saving.
diff --git a/src/platforms/rcore_android.c b/src/platforms/rcore_android.c
index 68ae979e..124a33c8 100644
--- a/src/platforms/rcore_android.c
+++ b/src/platforms/rcore_android.c
@@ -696,7 +696,7 @@ void PollInputEvents(void)
// NOTE: Never close window, native activity is controlled by the system!
if (platform.app->destroyRequested != 0)
{
- //CORE.Window.shouldClose = true;
+ CORE.Window.shouldClose = true;
//ANativeActivity_finish(platform.app->activity);
}
}
@@ -811,6 +811,11 @@ void ClosePlatform(void)
eglTerminate(platform.device);
platform.device = EGL_NO_DISPLAY;
}
+
+ if (platform.app->destroyRequested != 0) {
+ CORE = (CoreData){0};
+ platform = (PlatformData){0};
+ }
}
// Initialize display device and framebufferEnvironment
Platform: Android
Operating System: Android 11
OpenGL Version: GLES 3.2 (Tested app is using GLES 2.0)
GPU: N/A
Issue Screenshot
N/A
Code Example
Any example from examples/ will do, I tested with shapes/shapes_bouncing_ball