From bbf22a39c179cb055f2c9c4aeacc4dc50e53d715 Mon Sep 17 00:00:00 2001 From: Fredia Huya-Kouadio Date: Thu, 3 Jul 2025 09:43:24 -0700 Subject: [PATCH] Assign the `primaryHost` prior to initializing the registered Android plugins. Address a regression introduced in https://github.com/godotengine/godot/pull/102866. The proper behavior for Android plugins is to use `getContext` instead of `getActivity`, but since not all plugins follow this pattern, this fix provides backward compat to avoid breaking the plugins that don't. --- platform/android/java/lib/src/org/godotengine/godot/Godot.kt | 4 +++- .../java/lib/src/org/godotengine/godot/GodotFragment.java | 2 +- .../lib/src/org/godotengine/godot/service/GodotService.kt | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/platform/android/java/lib/src/org/godotengine/godot/Godot.kt b/platform/android/java/lib/src/org/godotengine/godot/Godot.kt index 051f2323a7..f43bb5cec7 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/Godot.kt +++ b/platform/android/java/lib/src/org/godotengine/godot/Godot.kt @@ -204,7 +204,7 @@ class Godot private constructor(val context: Context) { * @throws IllegalArgumentException exception if the specified expansion pack (if any) * is invalid. */ - fun initEngine(commandLineParams: List, hostPlugins: Set): Boolean { + fun initEngine(host: GodotHost?, commandLineParams: List, hostPlugins: Set = Collections.emptySet()): Boolean { if (isNativeInitialized()) { Log.d(TAG, "Engine already initialized") return true @@ -216,6 +216,8 @@ class Godot private constructor(val context: Context) { beginBenchmarkMeasure("Startup", "Godot::initEngine") try { + this.primaryHost = host + Log.v(TAG, "Initializing Godot plugin registry") val runtimePlugins = mutableSetOf(AndroidRuntimePlugin(this)) runtimePlugins.addAll(hostPlugins) diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotFragment.java b/platform/android/java/lib/src/org/godotengine/godot/GodotFragment.java index a32e7f8be9..4f76ba9457 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotFragment.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotFragment.java @@ -174,7 +174,7 @@ public class GodotFragment extends Fragment implements IDownloaderClient, GodotH private void performEngineInitialization() { try { - if (!godot.initEngine(getCommandLine(), getHostPlugins(godot))) { + if (!godot.initEngine(this, getCommandLine(), getHostPlugins(godot))) { throw new IllegalStateException("Unable to initialize Godot engine"); } diff --git a/platform/android/java/lib/src/org/godotengine/godot/service/GodotService.kt b/platform/android/java/lib/src/org/godotengine/godot/service/GodotService.kt index 34b5e91fb8..031fd0e653 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/service/GodotService.kt +++ b/platform/android/java/lib/src/org/godotengine/godot/service/GodotService.kt @@ -321,7 +321,7 @@ open class GodotService : Service() { Log.d(TAG, "Performing engine initialization") try { // Initialize the Godot instance - if (!godot.initEngine(godotHost.commandLine, godotHost.getHostPlugins(godot))) { + if (!godot.initEngine(godotHost, godotHost.commandLine, godotHost.getHostPlugins(godot))) { throw IllegalStateException("Unable to initialize Godot engine layer") }