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

(cherry picked from commit 81131bd844)
This commit is contained in:
Bastiaan Olij 2021-04-06 11:55:15 +10:00 committed by Rémi Verschelde
parent 48b7e73e44
commit 5228871e26
No known key found for this signature in database
GPG Key ID: C3336907360768E1

View File

@ -1502,6 +1502,11 @@ void NativeScriptLanguage::unregister_script(NativeScript *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()->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); Map<String, Map<StringName, NativeScriptDesc> >::Element *L = library_classes.find(script->lib_path);
if (L) { if (L) {
Map<StringName, NativeScriptDesc> classes = L->get(); Map<StringName, NativeScriptDesc> classes = L->get();
@ -1538,8 +1543,7 @@ void NativeScriptLanguage::unregister_script(NativeScript *script) {
library_classes.erase(script->lib_path); library_classes.erase(script->lib_path);
} }
Map<String, Ref<GDNative> >::Element *G = library_gdnatives.find(script->lib_path); // now unload the library
if (G && G->get()->get_library()->is_reloadable()) {
G->get()->terminate(); G->get()->terminate();
library_gdnatives.erase(G); library_gdnatives.erase(G);
} }