diff options
| author | Rémi Verschelde <rverschelde@gmail.com> | 2020-09-18 16:18:57 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-09-18 16:18:57 +0200 |
| commit | cff43e5326537dd0964ec84ec94382301b3c943b (patch) | |
| tree | 40ffe38c614ae2466802e8e30e68c3a4c5366a6a /modules/gdscript/gdscript.cpp | |
| parent | cb244f0b503f321cdb63e78ff2ea82da4192d868 (diff) | |
| parent | e25f5e791e709f44026ad933d5eada34a4715ef6 (diff) | |
| download | redot-engine-cff43e5326537dd0964ec84ec94382301b3c943b.tar.gz | |
Merge pull request #41930 from RandomShaper/fix_gdscript_leaks
Fix leaks in GDScript
Diffstat (limited to 'modules/gdscript/gdscript.cpp')
| -rw-r--r-- | modules/gdscript/gdscript.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index 0263e32c5b..7f303a966d 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -1053,7 +1053,9 @@ GDScript::~GDScript() { memdelete(E->get()); } - GDScriptCache::remove_script(get_path()); + if (GDScriptCache::singleton) { // Cache may have been already destroyed at engine shutdown. + GDScriptCache::remove_script(get_path()); + } _save_orphaned_subclasses(); @@ -2035,7 +2037,23 @@ GDScriptLanguage::~GDScriptLanguage() { if (_call_stack) { memdelete_arr(_call_stack); } - singleton = nullptr; + + // Clear dependencies between scripts, to ensure cyclic references are broken (to avoid leaks at exit). + while (script_list.first()) { + GDScript *script = script_list.first()->self(); + for (Map<StringName, GDScriptFunction *>::Element *E = script->member_functions.front(); E; E = E->next()) { + GDScriptFunction *func = E->get(); + for (int i = 0; i < func->argument_types.size(); i++) { + func->argument_types.write[i].script_type_ref = Ref<Script>(); + } + func->return_type.script_type_ref = Ref<Script>(); + } + for (Map<StringName, GDScript::MemberInfo>::Element *E = script->member_indices.front(); E; E = E->next()) { + E->get().data_type.script_type_ref = Ref<Script>(); + } + } + + singleton = NULL; } void GDScriptLanguage::add_orphan_subclass(const String &p_qualified_name, const ObjectID &p_subclass) { |
