Browse Source

Merge pull request #44617 from geekrelief/gdnative_unload

free library when no nativescripts reference it
Rémi Verschelde 4 years ago
parent
commit
f7dd6975fb
1 changed files with 6 additions and 0 deletions
  1. 6 0
      modules/gdnative/nativescript/nativescript.cpp

+ 6 - 0
modules/gdnative/nativescript/nativescript.cpp

@@ -1724,6 +1724,12 @@ void NativeScriptLanguage::unregister_script(NativeScript *script) {
 		S->get().erase(script);
 		S->get().erase(script);
 		if (S->get().size() == 0) {
 		if (S->get().size() == 0) {
 			library_script_users.erase(S);
 			library_script_users.erase(S);
+
+			Map<String, Ref<GDNative>>::Element *G = library_gdnatives.find(script->lib_path);
+			if (G) {
+				G->get()->terminate();
+				library_gdnatives.erase(G);
+			}
 		}
 		}
 	}
 	}
 #ifndef NO_THREADS
 #ifndef NO_THREADS