GDScript call stack as reverse linked list with fixed coroutines

* GDScript call stack as reverse linked list with issues fixed
(originally proposed in 91006).
* Fix coroutine issues with call stack by resuming async call chain
inside `GDScriptFunction::call()`.
* This fixes corrupted line numbers for coroutines in the debugger and
backtrace (106489).

Co-authored-by: Juan Linietsky <reduzio@gmail.com>
This commit is contained in:
Serhii Snitsaruk 2025-05-23 19:32:01 +02:00
parent e1b4101e34
commit a095c5e3fa
No known key found for this signature in database
GPG key ID: C658C84657FE945B
7 changed files with 90 additions and 79 deletions

View file

@ -2329,8 +2329,6 @@ void GDScriptLanguage::finish() {
}
finishing = true;
_call_stack.free();
// Clear the cache before parsing the script_list
GDScriptCache::clear();
@ -2922,7 +2920,19 @@ String GDScriptLanguage::get_global_class_name(const String &p_path, String *r_b
return c->identifier != nullptr ? String(c->identifier->name) : String();
}
thread_local GDScriptLanguage::CallStack GDScriptLanguage::_call_stack;
thread_local GDScriptLanguage::CallLevel *GDScriptLanguage::_call_stack = nullptr;
thread_local uint32_t GDScriptLanguage::_call_stack_size = 0;
GDScriptLanguage::CallLevel *GDScriptLanguage::_get_stack_level(uint32_t p_level) {
ERR_FAIL_UNSIGNED_INDEX_V(p_level, _call_stack_size, nullptr);
CallLevel *level = _call_stack; // Start from top
uint32_t level_index = 0;
while (p_level > level_index) {
level_index++;
level = level->prev;
}
return level;
}
GDScriptLanguage::GDScriptLanguage() {
ERR_FAIL_COND(singleton);