diff options
| author | Fredia Huya-Kouadio <fhuyakou@gmail.com> | 2024-05-19 15:48:30 -0700 |
|---|---|---|
| committer | Fredia Huya-Kouadio <fhuyakou@gmail.com> | 2024-05-19 19:27:04 -0700 |
| commit | 5a74e5812b3de4bd979f40f04e14e50a2bdaa386 (patch) | |
| tree | 4c5a58e56339118919ac62cd1fdc72a892049f1c /platform/android/plugin/godot_plugin_jni.cpp | |
| parent | daa81bbb7d1c6d75d1711595604178ee62a5801d (diff) | |
| download | redot-engine-5a74e5812b3de4bd979f40f04e14e50a2bdaa386.tar.gz | |
Add logic to unregister the Godot plugins on engine termination
Diffstat (limited to 'platform/android/plugin/godot_plugin_jni.cpp')
| -rw-r--r-- | platform/android/plugin/godot_plugin_jni.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/platform/android/plugin/godot_plugin_jni.cpp b/platform/android/plugin/godot_plugin_jni.cpp index fd60ba4ae7..e3cde145cb 100644 --- a/platform/android/plugin/godot_plugin_jni.cpp +++ b/platform/android/plugin/godot_plugin_jni.cpp @@ -40,16 +40,32 @@ static HashMap<String, JNISingleton *> jni_singletons; +void unregister_plugins_singletons() { + for (const KeyValue<String, JNISingleton *> &E : jni_singletons) { + Engine::get_singleton()->remove_singleton(E.key); + ProjectSettings::get_singleton()->set(E.key, Variant()); + + if (E.value) { + memdelete(E.value); + } + } + jni_singletons.clear(); +} + extern "C" { -JNIEXPORT void JNICALL Java_org_godotengine_godot_plugin_GodotPlugin_nativeRegisterSingleton(JNIEnv *env, jclass clazz, jstring name, jobject obj) { +JNIEXPORT jboolean JNICALL Java_org_godotengine_godot_plugin_GodotPlugin_nativeRegisterSingleton(JNIEnv *env, jclass clazz, jstring name, jobject obj) { String singname = jstring_to_string(name, env); + + ERR_FAIL_COND_V(jni_singletons.has(singname), false); + JNISingleton *s = (JNISingleton *)ClassDB::instantiate("JNISingleton"); s->set_instance(env->NewGlobalRef(obj)); jni_singletons[singname] = s; Engine::get_singleton()->add_singleton(Engine::Singleton(singname, s)); ProjectSettings::get_singleton()->set(singname, s); + return true; } JNIEXPORT void JNICALL Java_org_godotengine_godot_plugin_GodotPlugin_nativeRegisterMethod(JNIEnv *env, jclass clazz, jstring sname, jstring name, jstring ret, jobjectArray args) { |
