From 4d0da7401412edaba475de33d42a73ba8ca82cd3 Mon Sep 17 00:00:00 2001 From: Fredia Huya-Kouadio Date: Mon, 22 Jul 2024 17:51:45 -0700 Subject: Fix the cleanup logic for the Android render thread On Android the exit logic goes through `Godot#onDestroy()` who attempts to cleanup the engine using the following code: ``` runOnRenderThread { GodotLib.ondestroy() forceQuit() } ``` The issue however is that by the time we ran this code, the render thread has already been paused (but not yet destroyed), and thus `GodotLib.ondestroy()` and `forceQuit()` which are scheduled on the render thread are not executed. To address this, we instead explicitly request the render thread to exit and block until it does. As part of it exit logic, the render thread has been updated to properly destroy and clean the native instance of the Godot engine, resolving the issue. --- .../editor/src/main/java/org/godotengine/editor/GodotEditor.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'platform/android/java/editor/src') diff --git a/platform/android/java/editor/src/main/java/org/godotengine/editor/GodotEditor.kt b/platform/android/java/editor/src/main/java/org/godotengine/editor/GodotEditor.kt index 5515347bd6..7c11d69609 100644 --- a/platform/android/java/editor/src/main/java/org/godotengine/editor/GodotEditor.kt +++ b/platform/android/java/editor/src/main/java/org/godotengine/editor/GodotEditor.kt @@ -203,7 +203,14 @@ open class GodotEditor : GodotActivity() { } if (editorWindowInfo.windowClassName == javaClass.name) { Log.d(TAG, "Restarting ${editorWindowInfo.windowClassName} with parameters ${args.contentToString()}") - ProcessPhoenix.triggerRebirth(this, newInstance) + val godot = godot + if (godot != null) { + godot.destroyAndKillProcess { + ProcessPhoenix.triggerRebirth(this, newInstance) + } + } else { + ProcessPhoenix.triggerRebirth(this, newInstance) + } } else { Log.d(TAG, "Starting ${editorWindowInfo.windowClassName} with parameters ${args.contentToString()}") newInstance.putExtra(EXTRA_NEW_LAUNCH, true) -- cgit v1.2.3