From 9b96f8737724c481066d2e1bc2280c1de42ef136 Mon Sep 17 00:00:00 2001 From: karroffel Date: Thu, 18 Jan 2018 12:04:34 +0100 Subject: [PATCH] [GDNative] fix #15723 --- .../gdnative/nativescript/nativescript.cpp | 41 +++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp index cff5d9c9bdc..2216be02576 100644 --- a/modules/gdnative/nativescript/nativescript.cpp +++ b/modules/gdnative/nativescript/nativescript.cpp @@ -798,11 +798,33 @@ NativeScriptLanguage *NativeScriptLanguage::singleton; void NativeScriptLanguage::_unload_stuff(bool p_reload) { for (Map >::Element *L = library_classes.front(); L; L = L->next()) { - if (p_reload && library_gdnatives[L->key()].is_valid() && !library_gdnatives[L->key()]->get_library()->is_reloadable()) { - continue; + String lib_path = L->key(); + Map classes = L->get(); + + if (p_reload) { + + Map >::Element *E = library_gdnatives.find(lib_path); + Ref gdn; + + if (E) { + gdn = E->get(); + } + + bool should_reload = false; + + if (gdn.is_valid()) { + Ref lib = gdn->get_library(); + if (lib.is_valid()) { + should_reload = lib->is_reloadable(); + } + } + + if (!should_reload) { + continue; + } } - for (Map::Element *C = L->get().front(); C; C = C->next()) { + for (Map::Element *C = classes.front(); C; C = C->next()) { // free property stuff first for (OrderedHashMap::Element P = C->get().properties.front(); P; P = P.next()) { @@ -1063,6 +1085,11 @@ void NativeScriptLanguage::unregister_script(NativeScript *script) { void NativeScriptLanguage::call_libraries_cb(const StringName &name) { // library_gdnatives is modified only from the main thread, so it's safe not to use mutex here for (Map >::Element *L = library_gdnatives.front(); L; L = L->next()) { + + if (L->get().is_null()) { + continue; + } + if (L->get()->is_initialized()) { void *proc_ptr; @@ -1125,6 +1152,10 @@ void NativeReloadNode::_notification(int p_what) { Ref gdn = L->get(); + if (gdn.is_null()) { + continue; + } + if (!gdn->get_library()->is_reloadable()) { continue; } @@ -1149,6 +1180,10 @@ void NativeReloadNode::_notification(int p_what) { Ref gdn = L->get(); + if (gdn.is_null()) { + continue; + } + if (!gdn->get_library()->is_reloadable()) { continue; }