diff options
author | Pedro J. Estébanez <pedrojrulez@gmail.com> | 2020-05-05 12:53:05 +0200 |
---|---|---|
committer | Pedro J. Estébanez <pedrojrulez@gmail.com> | 2020-05-05 17:54:15 +0200 |
commit | 46bfe4452f44d0264346227abc3431c76ee717dc (patch) | |
tree | 57ea824058e822f4aa5b4e75622a6f6edab24bb5 /core/self_list.h | |
parent | 1c23a0cc7f879774f56404378db1bf86979e42d1 (diff) | |
download | redot-engine-46bfe4452f44d0264346227abc3431c76ee717dc.tar.gz |
Fix object leaks caused by unfulfilled yields
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.
Diffstat (limited to 'core/self_list.h')
-rw-r--r-- | core/self_list.h | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/core/self_list.h b/core/self_list.h index 19d2783208..43aeb44fea 100644 --- a/core/self_list.h +++ b/core/self_list.h @@ -120,6 +120,9 @@ private: public: _FORCE_INLINE_ bool in_list() const { return _root; } + _FORCE_INLINE_ void remove_from_list() { + if (_root) _root->remove(this); + } _FORCE_INLINE_ SelfList<T> *next() { return _next; } _FORCE_INLINE_ SelfList<T> *prev() { return _prev; } _FORCE_INLINE_ const SelfList<T> *next() const { return _next; } |