Only cleanup meta data if GDNative library is reloadable and we're about to unload it

This commit is contained in:
Bastiaan Olij 2021-04-06 11:55:15 +10:00
parent f4b82814f8
commit 81131bd844

View File

@ -1727,6 +1727,11 @@ void NativeScriptLanguage::unregister_script(NativeScript *script) {
if (S->get().size() == 0) {
library_script_users.erase(S);
Map<String, Ref<GDNative>>::Element *G = library_gdnatives.find(script->lib_path);
if (G && G->get()->get_library()->is_reloadable()) {
// ONLY if the library is marked as reloadable, and no more instances of its scripts exist do we unload the library
// First remove meta data related to the library
Map<String, Map<StringName, NativeScriptDesc>>::Element *L = library_classes.find(script->lib_path);
if (L) {
Map<StringName, NativeScriptDesc> classes = L->get();
@ -1763,8 +1768,7 @@ void NativeScriptLanguage::unregister_script(NativeScript *script) {
library_classes.erase(script->lib_path);
}
Map<String, Ref<GDNative>>::Element *G = library_gdnatives.find(script->lib_path);
if (G && G->get()->get_library()->is_reloadable()) {
// now unload the library
G->get()->terminate();
library_gdnatives.erase(G);
}