Skip to content

Commit 3e14ac0

Browse files
GDScript: Destruct remaining instances when language is finished
1 parent 6d6e822 commit 3e14ac0

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

modules/gdscript/gdscript.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,6 +2192,15 @@ void GDScriptLanguage::finish() {
21922192
}
21932193
finishing = true;
21942194

2195+
// Destruct and detach instances that still exist.
2196+
// Other systems might try to call/destruct them which will crash if `GDScriptLanguage` is not around anymore.
2197+
for (const SelfList<GDScript> *E = script_list.first(); E != nullptr; E = E->next()) {
2198+
const Ref<GDScript> script = E->self();
2199+
while (script->instances.first() != nullptr) {
2200+
script->instances.first()->self()->get_owner()->set_script(Variant());
2201+
}
2202+
}
2203+
21952204
// Clear the cache before parsing the script_list
21962205
GDScriptCache::clear();
21972206

0 commit comments

Comments
 (0)