From 58fa4973f604a3e5c8f425ddbec3cea405fb20a8 Mon Sep 17 00:00:00 2001 From: geekrelief Date: Tue, 9 Mar 2021 14:28:52 -0800 Subject: fixes #46839, ensure library_classes is cleared and free funcs are called Co-authored-by: toasteater <48371905+toasteater@users.noreply.github.com> Co-authored-by: Jan Haller --- modules/gdnative/nativescript/nativescript.cpp | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp index 1bdbb0b03b..0b066dfe97 100644 --- a/modules/gdnative/nativescript/nativescript.cpp +++ b/modules/gdnative/nativescript/nativescript.cpp @@ -1727,6 +1727,40 @@ void NativeScriptLanguage::unregister_script(NativeScript *script) { if (S->get().size() == 0) { library_script_users.erase(S); + Map>::Element *L = library_classes.find(script->lib_path); + if (L) { + Map classes = L->get(); + + 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()) { + if (P.get().getter.free_func) { + P.get().getter.free_func(P.get().getter.method_data); + } + + if (P.get().setter.free_func) { + P.get().setter.free_func(P.get().setter.method_data); + } + } + + // free method stuff + for (Map::Element *M = C->get().methods.front(); M; M = M->next()) { + if (M->get().method.free_func) { + M->get().method.free_func(M->get().method.method_data); + } + } + + // free constructor/destructor + if (C->get().create_func.free_func) { + C->get().create_func.free_func(C->get().create_func.method_data); + } + + if (C->get().destroy_func.free_func) { + C->get().destroy_func.free_func(C->get().destroy_func.method_data); + } + } + } + Map>::Element *G = library_gdnatives.find(script->lib_path); if (G && G->get()->get_library()->is_reloadable()) { G->get()->terminate(); -- cgit v1.2.3