You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-12 13:20:55 +00:00
Fix leaked objects when game ends with yields in progress
This commit is contained in:
@@ -294,11 +294,10 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
|
|||||||
line = p_state->line;
|
line = p_state->line;
|
||||||
ip = p_state->ip;
|
ip = p_state->ip;
|
||||||
alloca_size = p_state->stack.size();
|
alloca_size = p_state->stack.size();
|
||||||
script = p_state->script.ptr();
|
script = static_cast<GDScript *>(ObjectDB::get_instance(p_state->script_id));
|
||||||
p_instance = p_state->instance;
|
p_instance = p_state->instance_id.is_valid() ? static_cast<GDScriptInstance *>(ObjectDB::get_instance(p_state->instance_id)->get_script_instance()) : nullptr;
|
||||||
defarg = p_state->defarg;
|
defarg = p_state->defarg;
|
||||||
self = p_state->self;
|
self = p_state->self;
|
||||||
//stack[p_state->result_pos]=p_state->result; //assign stack with result
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@@ -1280,13 +1279,14 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
|
|||||||
gdfs->state.stack_size = _stack_size;
|
gdfs->state.stack_size = _stack_size;
|
||||||
gdfs->state.self = self;
|
gdfs->state.self = self;
|
||||||
gdfs->state.alloca_size = alloca_size;
|
gdfs->state.alloca_size = alloca_size;
|
||||||
gdfs->state.script = Ref<GDScript>(_script);
|
|
||||||
gdfs->state.ip = ip + ipofs;
|
gdfs->state.ip = ip + ipofs;
|
||||||
gdfs->state.line = line;
|
gdfs->state.line = line;
|
||||||
|
gdfs->state.script_id = script->get_instance_id();
|
||||||
|
#ifdef DEBUG_ENABLED
|
||||||
|
gdfs->state.script_path = _script->get_path();
|
||||||
|
#endif
|
||||||
gdfs->state.instance_id = (p_instance && p_instance->get_owner()) ? p_instance->get_owner()->get_instance_id() : ObjectID();
|
gdfs->state.instance_id = (p_instance && p_instance->get_owner()) ? p_instance->get_owner()->get_instance_id() : ObjectID();
|
||||||
//gdfs->state.result_pos=ip+ipofs-1;
|
|
||||||
gdfs->state.defarg = defarg;
|
gdfs->state.defarg = defarg;
|
||||||
gdfs->state.instance = p_instance;
|
|
||||||
gdfs->function = this;
|
gdfs->function = this;
|
||||||
|
|
||||||
retvalue = gdfs;
|
retvalue = gdfs;
|
||||||
@@ -1833,10 +1833,15 @@ bool GDScriptFunctionState::is_valid(bool p_extended_check) const {
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (p_extended_check) {
|
if (p_extended_check) {
|
||||||
//class instance gone?
|
// Class instance gone? (Otherwise script is valid for sure, because the instance has a ref to the script)
|
||||||
if (state.instance_id.is_valid() && !ObjectDB::get_instance(state.instance_id))
|
if (state.instance_id.is_valid() && !ObjectDB::get_instance(state.instance_id)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// Script gone? (Static method, so there's no instance whose ref to the script can ensure it's valid)
|
||||||
|
if (!ObjectDB::get_instance(state.script_id)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1846,7 +1851,14 @@ Variant GDScriptFunctionState::resume(const Variant &p_arg) {
|
|||||||
ERR_FAIL_COND_V(!function, Variant());
|
ERR_FAIL_COND_V(!function, Variant());
|
||||||
if (state.instance_id.is_valid() && !ObjectDB::get_instance(state.instance_id)) {
|
if (state.instance_id.is_valid() && !ObjectDB::get_instance(state.instance_id)) {
|
||||||
#ifdef DEBUG_ENABLED
|
#ifdef DEBUG_ENABLED
|
||||||
ERR_FAIL_V_MSG(Variant(), "Resumed function '" + String(function->get_name()) + "()' after yield, but class instance is gone. At script: " + state.script->get_path() + ":" + itos(state.line));
|
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));
|
||||||
|
#else
|
||||||
|
return Variant();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
if (!ObjectDB::get_instance(state.script_id)) {
|
||||||
|
#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));
|
||||||
#else
|
#else
|
||||||
return Variant();
|
return Variant();
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -293,13 +293,15 @@ private:
|
|||||||
public:
|
public:
|
||||||
struct CallState {
|
struct CallState {
|
||||||
|
|
||||||
|
ObjectID script_id;
|
||||||
|
#ifdef DEBUG_ENABLED
|
||||||
|
String script_path;
|
||||||
|
#endif
|
||||||
ObjectID instance_id;
|
ObjectID instance_id;
|
||||||
GDScriptInstance *instance;
|
|
||||||
Vector<uint8_t> stack;
|
Vector<uint8_t> stack;
|
||||||
int stack_size;
|
int stack_size;
|
||||||
Variant self;
|
Variant self;
|
||||||
uint32_t alloca_size;
|
uint32_t alloca_size;
|
||||||
Ref<GDScript> script;
|
|
||||||
int ip;
|
int ip;
|
||||||
int line;
|
int line;
|
||||||
int defarg;
|
int defarg;
|
||||||
|
|||||||
Reference in New Issue
Block a user