From 5a74e5812b3de4bd979f40f04e14e50a2bdaa386 Mon Sep 17 00:00:00 2001 From: Fredia Huya-Kouadio Date: Sun, 19 May 2024 15:48:30 -0700 Subject: Add logic to unregister the Godot plugins on engine termination --- .../org/godotengine/godot/plugin/GodotPlugin.java | 22 ++++++++++------------ .../android/java/nativeSrcsConfigs/CMakeLists.txt | 4 +++- 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'platform/android/java') diff --git a/platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPlugin.java b/platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPlugin.java index c0912ca4dc..c975c29e96 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPlugin.java +++ b/platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPlugin.java @@ -112,19 +112,18 @@ public abstract class GodotPlugin { /** * Register the plugin with Godot native code. *

- * This method is invoked by the Godot Engine on the render thread. + * This method is invoked on the render thread to register the plugin on engine startup. */ public final void onRegisterPluginWithGodotNative() { - registeredSignals.putAll( - registerPluginWithGodotNative(this, getPluginName(), getPluginMethods(), getPluginSignals())); - } + final String pluginName = getPluginName(); + if (!nativeRegisterSingleton(pluginName, this)) { + return; + } - private static Map registerPluginWithGodotNative(Object pluginObject, - String pluginName, List pluginMethods, Set pluginSignals) { - nativeRegisterSingleton(pluginName, pluginObject); + List pluginMethods = getPluginMethods(); Set filteredMethods = new HashSet<>(); - Class clazz = pluginObject.getClass(); + Class clazz = getClass(); Method[] methods = clazz.getDeclaredMethods(); for (Method method : methods) { @@ -156,15 +155,14 @@ public abstract class GodotPlugin { nativeRegisterMethod(pluginName, method.getName(), method.getReturnType().getName(), pt); } + Set pluginSignals = getPluginSignals(); + // Register the signals for this plugin. - Map registeredSignals = new HashMap<>(); for (SignalInfo signalInfo : pluginSignals) { String signalName = signalInfo.getName(); nativeRegisterSignal(pluginName, signalName, signalInfo.getParamTypesNames()); registeredSignals.put(signalName, signalInfo); } - - return registeredSignals; } /** @@ -408,7 +406,7 @@ public abstract class GodotPlugin { * Used to setup a {@link GodotPlugin} instance. * @param p_name Name of the instance. */ - private static native void nativeRegisterSingleton(String p_name, Object object); + private static native boolean nativeRegisterSingleton(String p_name, Object object); /** * Used to complete registration of the {@link GodotPlugin} instance's methods. diff --git a/platform/android/java/nativeSrcsConfigs/CMakeLists.txt b/platform/android/java/nativeSrcsConfigs/CMakeLists.txt index e1534c7685..96b6dfc9f3 100644 --- a/platform/android/java/nativeSrcsConfigs/CMakeLists.txt +++ b/platform/android/java/nativeSrcsConfigs/CMakeLists.txt @@ -7,6 +7,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) set(GODOT_ROOT_DIR ../../../..) +set(ANDROID_ROOT_DIR "${GODOT_ROOT_DIR}/platform/android" CACHE STRING "") # Get sources file(GLOB_RECURSE SOURCES ${GODOT_ROOT_DIR}/*.c**) @@ -15,6 +16,7 @@ file(GLOB_RECURSE HEADERS ${GODOT_ROOT_DIR}/*.h**) add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS}) target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC - ${GODOT_ROOT_DIR}) + ${GODOT_ROOT_DIR} + ${ANDROID_ROOT_DIR}) add_definitions(-DUNIX_ENABLED -DVULKAN_ENABLED -DANDROID_ENABLED -DGLES3_ENABLED -DTOOLS_ENABLED) -- cgit v1.2.3