Status Update
Comments
vr...@google.com <vr...@google.com>
ha...@gmail.com <ha...@gmail.com> #2
For starters, there is a bug in android_native_app_glue.c
.
In android_main
, when calling GameActivity_finish(pAndroidApp->activity)
the game correctly exits. However, when resuming the game, we end up in the onPause
callback even though android_app->destroyed
is set:
static void android_app_set_activity_state(struct android_app* android_app,
int8_t cmd) {
pthread_mutex_lock(&android_app->mutex);
android_app_write_cmd(android_app, cmd);
while (android_app->activityState != cmd) {
pthread_cond_wait(&android_app->cond, &android_app->mutex); // Deadlock? Waits forever...
}
pthread_mutex_unlock(&android_app->mutex);
}
When we get here, the android_app
struct contains these relevant values:
onAppCmd NULL
msgread 115
msgwrite 116
activityState 12
running 1
destroyed 1
ha...@gmail.com <ha...@gmail.com> #3
Additional notes. In GameActivity
class, the GameActivity_finish()
call makes us hang in onPause()
:
protected void onPause() {
super.onPause();
this.onPauseNative(this.mNativeHandle); // Hangs here!
}
So we try to finish the activity, but it resumes and then pauses. Really odd! The
Its finish() method will be called, causing it to be stopped and destroyed.
ha...@gmail.com <ha...@gmail.com> #4
Apparently, some integrations out there have patched this locally. E.g. See this PR:
Most of us are using prefab
though, so we cannot patch the glue code...
ha...@gmail.com <ha...@gmail.com> #5
I created a sample project demonstrating the deadlock. Just run it from Android Studio, and it will immediately hang in GameActivity.OnPause()
.
ha...@gmail.com <ha...@gmail.com> #6
If you check your Google Play logs, you will probably find some million crashes related to this. It's easy to reproduce, and I have observed similar crashes in many popular games out there. I.e. You leave the game, you return to it many hours later, it crashes after a second or so, you restart it and it works.
Many engines out there are adopting GameActivity
. Please provide a fix or workaround.
Description
Running
Android 15
onPixel 9 Pro
. Latest and greatest! :)We have successfully integrated
games-activity:3.0.5
(usingndk 27.2.12479018
). However, we have found a way to seemingly load the native library twice. Most likelyagdk-tunnel
sample also suffers from this.Steps to reproduce
Don't keep activities
setting in Developer Options.Repeat step 2 until you see this in
logcat
(or your app crashes due to some re-entrancy problem).Since we initialize
Paddleboat
andGameTextInput
inandroid_main()
there is no way we could have called those init methods twice. Unless, of course, the activity was created twice. I.e. The new activity instance is created just before we reach the end ofandroid_main()
where we have e.g.Paddleboat_destroy()
.LaunchMode needed for GameActivity?
So I'm wondering if launchMode setting in
GameActivity
should have a specialAndroidManifest.xml
, likesingleInstance
? It kind of makes sense, but I couldn't find anything about this in the docs.