diff options
author | Max Hilbrunner <mhilbrunner@users.noreply.github.com> | 2018-07-03 18:51:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-03 18:51:13 +0200 |
commit | aad475937bf2c36912981be7ce016f0de1fb6314 (patch) | |
tree | d1697462126f3034211a20fe759dad3a3e9f6b90 | |
parent | 465edbd2bc218cde1b4f90ac77f8ae4b817b4f26 (diff) | |
parent | 30317296af1124e2092d3acd374ca0246afd5536 (diff) |
Merge pull request #19828 from jjay/fix_yield_leak
Fix memory leak in GDScript during infinnity loops with yields
-rw-r--r-- | modules/gdscript/gdscript_function.cpp | 20 | ||||
-rw-r--r-- | modules/gdscript/gdscript_function.h | 2 |
2 files changed, 11 insertions, 11 deletions
diff --git a/modules/gdscript/gdscript_function.cpp b/modules/gdscript/gdscript_function.cpp index 61130cb58f..10599f0c38 100644 --- a/modules/gdscript/gdscript_function.cpp +++ b/modules/gdscript/gdscript_function.cpp @@ -1552,7 +1552,7 @@ Variant GDScriptFunctionState::_signal_callback(const Variant **p_args, int p_ar GDScriptFunctionState *gdfs = Object::cast_to<GDScriptFunctionState>(ret); if (gdfs && gdfs->function == function) { completed = false; - gdfs->previous_state = Ref<GDScriptFunctionState>(this); + gdfs->first_state = first_state.is_valid() ? first_state : Ref<GDScriptFunctionState>(this); } } @@ -1560,10 +1560,10 @@ Variant GDScriptFunctionState::_signal_callback(const Variant **p_args, int p_ar state.result = Variant(); if (completed) { - GDScriptFunctionState *state = this; - while (state != NULL) { - state->emit_signal("completed", ret); - state = *(state->previous_state); + if (first_state.is_valid()) { + first_state->emit_signal("completed", ret); + } else { + emit_signal("completed", ret); } } @@ -1614,7 +1614,7 @@ Variant GDScriptFunctionState::resume(const Variant &p_arg) { GDScriptFunctionState *gdfs = Object::cast_to<GDScriptFunctionState>(ret); if (gdfs && gdfs->function == function) { completed = false; - gdfs->previous_state = Ref<GDScriptFunctionState>(this); + gdfs->first_state = first_state.is_valid() ? first_state : Ref<GDScriptFunctionState>(this); } } @@ -1622,10 +1622,10 @@ Variant GDScriptFunctionState::resume(const Variant &p_arg) { state.result = Variant(); if (completed) { - GDScriptFunctionState *state = this; - while (state != NULL) { - state->emit_signal("completed", ret); - state = *(state->previous_state); + if (first_state.is_valid()) { + first_state->emit_signal("completed", ret); + } else { + emit_signal("completed", ret); } } diff --git a/modules/gdscript/gdscript_function.h b/modules/gdscript/gdscript_function.h index 836325f0fe..770d5c8733 100644 --- a/modules/gdscript/gdscript_function.h +++ b/modules/gdscript/gdscript_function.h @@ -234,7 +234,7 @@ class GDScriptFunctionState : public Reference { GDScriptFunction *function; GDScriptFunction::CallState state; Variant _signal_callback(const Variant **p_args, int p_argcount, Variant::CallError &r_error); - Ref<GDScriptFunctionState> previous_state; + Ref<GDScriptFunctionState> first_state; protected: static void _bind_methods(); |