Now the stack saved in a `GDScriptFunctionState` is cleared as soon as the `yield()` operation is known not to be resumed because either the script, the instance or both are deleted.
This clears problems like leaked objects by eliminating cases of circular references between `GDScriptFunctionState`s preventing them and the objects they refer to in their saved stacks from being released. As an example, this makes using `SceneTreeTimer` safer.
Furthermore, with this change it's now possible to print early warnings about `yield()`s to released script/instances, as now we know they won't be successfully resumed as the condition for that happens. However, this PR doesn't add such messages, to keep the observed behavior the same for the time being.
Also, now a backup of the function name in `GDScriptFunctionState` is used, since the script may not be valid by the time the function name is needed for the resume-after-yield error messages.
ERR_FAIL_V_MSG(Variant(),"Resumed function '"+String(function->get_name())+"()' after yield, but class instance is gone. At script: "+state.script_path+":"+itos(state.line));
ERR_FAIL_V_MSG(Variant(),"Resumed function '"+state.function_name+"()' after yield, but script is gone. At script: "+state.script_path+":"+itos(state.line));
#else
returnVariant();
#endif
}
}else{
if(!ObjectDB::get_instance(state.script_id)){
if(state.instance&&!instances_list.in_list()){
#ifdef DEBUG_ENABLED
ERR_FAIL_V_MSG(Variant(),"Resumed function '"+String(function->get_name())+"()' after yield, but script is gone. At script: "+state.script_path+":"+itos(state.line));
ERR_FAIL_V_MSG(Variant(),"Resumed function '"+state.function_name+"()' after yield, but class instance is gone. At script: "+state.script_path+":"+itos(state.line));
#else
returnVariant();
#endif
}
// Do these now to avoid locking again after the call