From 0b92aded232d1d4dad209dc65b049511acfe05ce Mon Sep 17 00:00:00 2001 From: karroffel Date: Sat, 31 Mar 2018 01:45:18 +0200 Subject: [GDNative] fixed issue with library unloading order --- modules/gdnative/nativescript/nativescript.cpp | 38 +++++++++++++++++--------- 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'modules/gdnative/nativescript/nativescript.cpp') diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp index 5806ee3f3f..ff31035036 100644 --- a/modules/gdnative/nativescript/nativescript.cpp +++ b/modules/gdnative/nativescript/nativescript.cpp @@ -881,6 +881,9 @@ NativeScriptInstance::~NativeScriptInstance() { NativeScriptLanguage *NativeScriptLanguage::singleton; void NativeScriptLanguage::_unload_stuff(bool p_reload) { + + Map > erase_and_unload; + for (Map >::Element *L = library_classes.front(); L; L = L->next()) { String lib_path = L->key(); @@ -916,18 +919,6 @@ void NativeScriptLanguage::_unload_stuff(bool p_reload) { gdn = E->get(); } - if (gdn.is_valid() && gdn->get_library().is_valid()) { - Ref lib = gdn->get_library(); - void *terminate_fn; - Error err = gdn->get_symbol(lib->get_symbol_prefix() + _terminate_call_name, terminate_fn, true); - - if (err == OK) { - void (*terminate)(void *) = (void (*)(void *))terminate_fn; - - terminate((void *)&lib_path); - } - } - for (Map::Element *C = classes.front(); C; C = C->next()) { // free property stuff first @@ -952,6 +943,27 @@ void NativeScriptLanguage::_unload_stuff(bool p_reload) { if (C->get().destroy_func.free_func) C->get().destroy_func.free_func(C->get().destroy_func.method_data); } + + erase_and_unload.insert(lib_path, gdn); + } + + for (Map >::Element *E = erase_and_unload.front(); E; E = E->next()) { + String lib_path = E->key(); + Ref gdn = E->get(); + + library_classes.erase(lib_path); + + if (gdn.is_valid() && gdn->get_library().is_valid()) { + Ref lib = gdn->get_library(); + void *terminate_fn; + Error err = gdn->get_symbol(lib->get_symbol_prefix() + _terminate_call_name, terminate_fn, true); + + if (err == OK) { + void (*terminate)(void *) = (void (*)(void *))terminate_fn; + + terminate((void *)&lib_path); + } + } } } @@ -1363,6 +1375,7 @@ void NativeReloadNode::_notification(int p_what) { MutexLock lock(NSL->mutex); #endif NSL->_unload_stuff(true); + for (Map >::Element *L = NSL->library_gdnatives.front(); L; L = L->next()) { Ref gdn = L->get(); @@ -1376,7 +1389,6 @@ void NativeReloadNode::_notification(int p_what) { } gdn->terminate(); - NSL->library_classes.erase(L->key()); } unloaded = true; -- cgit v1.2.3