Fix memory leak in GDScript during infinnity loops with yields
(cherry picked from commit 30317296af
)
This commit is contained in:
parent
dae30964a2
commit
f17983e9cf
|
@ -1537,7 +1537,7 @@ Variant GDScriptFunctionState::_signal_callback(const Variant **p_args, int p_ar
|
||||||
GDScriptFunctionState *gdfs = Object::cast_to<GDScriptFunctionState>(ret);
|
GDScriptFunctionState *gdfs = Object::cast_to<GDScriptFunctionState>(ret);
|
||||||
if (gdfs && gdfs->function == function) {
|
if (gdfs && gdfs->function == function) {
|
||||||
completed = false;
|
completed = false;
|
||||||
gdfs->previous_state = Ref<GDScriptFunctionState>(this);
|
gdfs->first_state = first_state.is_valid() ? first_state : Ref<GDScriptFunctionState>(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1545,10 +1545,10 @@ Variant GDScriptFunctionState::_signal_callback(const Variant **p_args, int p_ar
|
||||||
state.result = Variant();
|
state.result = Variant();
|
||||||
|
|
||||||
if (completed) {
|
if (completed) {
|
||||||
GDScriptFunctionState *state = this;
|
if (first_state.is_valid()) {
|
||||||
while (state != NULL) {
|
first_state->emit_signal("completed", ret);
|
||||||
state->emit_signal("completed", ret);
|
} else {
|
||||||
state = *(state->previous_state);
|
emit_signal("completed", ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1599,7 +1599,7 @@ Variant GDScriptFunctionState::resume(const Variant &p_arg) {
|
||||||
GDScriptFunctionState *gdfs = Object::cast_to<GDScriptFunctionState>(ret);
|
GDScriptFunctionState *gdfs = Object::cast_to<GDScriptFunctionState>(ret);
|
||||||
if (gdfs && gdfs->function == function) {
|
if (gdfs && gdfs->function == function) {
|
||||||
completed = false;
|
completed = false;
|
||||||
gdfs->previous_state = Ref<GDScriptFunctionState>(this);
|
gdfs->first_state = first_state.is_valid() ? first_state : Ref<GDScriptFunctionState>(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1607,10 +1607,10 @@ Variant GDScriptFunctionState::resume(const Variant &p_arg) {
|
||||||
state.result = Variant();
|
state.result = Variant();
|
||||||
|
|
||||||
if (completed) {
|
if (completed) {
|
||||||
GDScriptFunctionState *state = this;
|
if (first_state.is_valid()) {
|
||||||
while (state != NULL) {
|
first_state->emit_signal("completed", ret);
|
||||||
state->emit_signal("completed", ret);
|
} else {
|
||||||
state = *(state->previous_state);
|
emit_signal("completed", ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -234,7 +234,7 @@ class GDScriptFunctionState : public Reference {
|
||||||
GDScriptFunction *function;
|
GDScriptFunction *function;
|
||||||
GDScriptFunction::CallState state;
|
GDScriptFunction::CallState state;
|
||||||
Variant _signal_callback(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
|
Variant _signal_callback(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
|
||||||
Ref<GDScriptFunctionState> previous_state;
|
Ref<GDScriptFunctionState> first_state;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
Loading…
Reference in New Issue