You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-07 12:30:27 +00:00
Add logic to unregister the Godot plugins on engine termination
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user