summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorRémi Verschelde <remi@verschelde.fr>2021-03-29 16:11:11 +0200
committerGitHub <noreply@github.com>2021-03-29 16:11:11 +0200
commit58d302dd5fc2bd5307ca06a6a0f5b2be43403243 (patch)
tree10421c4169cd02d213059bc1b937b59edb18c4e6 /modules
parenta6d190ebc58b84b860be196830955a17243779fc (diff)
parent58fa4973f604a3e5c8f425ddbec3cea405fb20a8 (diff)
Merge pull request #46844 from geekrelief/gdnative_unregister_script_fix
fixes #46839, ensure library_classes is cleared and free funcs are ca…
Diffstat (limited to 'modules')
-rw-r--r--modules/gdnative/nativescript/nativescript.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp
index 0025f4bb06..5d2117d76c 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<String, Map<StringName, NativeScriptDesc>>::Element *L = library_classes.find(script->lib_path);
+ if (L) {
+ Map<StringName, NativeScriptDesc> classes = L->get();
+
+ for (Map<StringName, NativeScriptDesc>::Element *C = classes.front(); C; C = C->next()) {
+ // free property stuff first
+ for (OrderedHashMap<StringName, NativeScriptDesc::Property>::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<StringName, NativeScriptDesc::Method>::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<String, Ref<GDNative>>::Element *G = library_gdnatives.find(script->lib_path);
if (G && G->get()->get_library()->is_reloadable()) {
G->get()->terminate();