rust-mobile / android-activity

Glue for building Rust applications on Android with NativeActivity or GameActivity
251 stars 49 forks source link

Fix deadlocks in game-activity backend if java callbacks are fired after native thread exits #97

Closed rib closed 1 year ago

rib commented 1 year ago

See the discussion here for more context: https://github.com/rust-mobile/android-activity/pull/94#issuecomment-1652014915

Essentially the GameActivity backend doesn't have checks within its Java Activity callbacks that check whether the android_app has already been destroyed (e.g. due to a graceful exit by returning from android_main

Since android-activity will issue a GameActivity_finish when android_main returns that will result in onPause -> onStop -> onDestroyed lifecycled events in Java after the native thread for android_main has exit and then because the GameActivity callbacks don't check if the android_app is detroyed they deadlock waiting for the native thread to handle these lifecycle events.