GDScript: Fix and simplify coroutine stack clearing

This commit is contained in:
Danil Alexeev 2026-03-04 10:24:08 +03:00
parent 74b5be24f4
commit 8a09a2f88c
No known key found for this signature in database
GPG key ID: 5A52F75A8679EC57
5 changed files with 72 additions and 36 deletions

View file

@ -325,7 +325,7 @@ Variant GDScriptFunctionState::resume(const Variant &p_arg) {
return Variant();
#endif
}
// Do these now to avoid locking again after the call
// Do these now to avoid locking again after the call.
scripts_list.remove_from_list();
instances_list.remove_from_list();
}
@ -334,26 +334,9 @@ Variant GDScriptFunctionState::resume(const Variant &p_arg) {
Callable::CallError err;
Variant ret = function->call(nullptr, nullptr, 0, err, &state);
bool completed = true;
// If the return value is a GDScriptFunctionState reference,
// then the function did await again after resuming.
if (ret.is_ref_counted()) {
GDScriptFunctionState *gdfs = Object::cast_to<GDScriptFunctionState>(ret);
if (gdfs && gdfs->function == function) {
completed = false;
// Keep the first state alive via reference.
gdfs->first_state = first_state.is_valid() ? first_state : Ref<GDScriptFunctionState>(this);
}
}
function = nullptr; //cleaned up;
function = nullptr; // Cleaned up.
state.result = Variant();
if (completed) {
_clear_stack();
}
return ret;
}