Skip to content

Commit

Permalink
fixes godotengine#46839, ensure library_classes is cleared and free f…
Browse files Browse the repository at this point in the history
…uncs are called

Co-authored-by: toasteater <[email protected]>
Co-authored-by: Jan Haller <[email protected]>
  • Loading branch information
3 people committed Mar 9, 2021
1 parent 0bef220 commit 58fa497
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions modules/gdnative/nativescript/nativescript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 58fa497

Please sign in to comment.