File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed
Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -1537,10 +1537,14 @@ void GDScript::clear(ClearData *p_clear_data) {
15371537 }
15381538 }
15391539
1540- RBSet<GDScript *> must_clear_dependencies = get_must_clear_dependencies ();
1541- for (GDScript *E : must_clear_dependencies) {
1542- clear_data->scripts .insert (E);
1543- E->clear (clear_data);
1540+ // If we're in the process of shutting things down then every single script will be cleared
1541+ // anyway, so we can safely skip this very costly operation.
1542+ if (!GDScriptLanguage::singleton->finishing ) {
1543+ RBSet<GDScript *> must_clear_dependencies = get_must_clear_dependencies ();
1544+ for (GDScript *E : must_clear_dependencies) {
1545+ clear_data->scripts .insert (E);
1546+ E->clear (clear_data);
1547+ }
15441548 }
15451549
15461550 for (const KeyValue<StringName, GDScriptFunction *> &E : member_functions) {
@@ -2246,6 +2250,11 @@ String GDScriptLanguage::get_extension() const {
22462250}
22472251
22482252void GDScriptLanguage::finish () {
2253+ if (finishing) {
2254+ return ;
2255+ }
2256+ finishing = true ;
2257+
22492258 _call_stack.free ();
22502259
22512260 // Clear the cache before parsing the script_list
@@ -2281,6 +2290,8 @@ void GDScriptLanguage::finish() {
22812290 }
22822291 script_list.clear ();
22832292 function_list.clear ();
2293+
2294+ finishing = false ;
22842295}
22852296
22862297void GDScriptLanguage::profiling_start () {
Original file line number Diff line number Diff line change @@ -411,6 +411,8 @@ class GDScriptLanguage : public ScriptLanguage {
411411
412412 static GDScriptLanguage *singleton;
413413
414+ bool finishing = false ;
415+
414416 Variant *_global_array = nullptr ;
415417 Vector<Variant> global_array;
416418 HashMap<StringName, int > globals;
You can’t perform that action at this time.
0 commit comments