Fix crash on signal/resume to dangling target
This commit is contained in:
parent
b499537e68
commit
06b6cea62e
|
@ -275,7 +275,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint32_t alloca_size = 0;
|
uint32_t alloca_size = 0;
|
||||||
GDScript *_class;
|
GDScript *script;
|
||||||
int ip = 0;
|
int ip = 0;
|
||||||
int line = _initial_line;
|
int line = _initial_line;
|
||||||
|
|
||||||
|
@ -286,7 +286,7 @@ 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();
|
||||||
_class = p_state->_class;
|
script = p_state->script.ptr();
|
||||||
p_instance = p_state->instance;
|
p_instance = p_state->instance;
|
||||||
defarg = p_state->defarg;
|
defarg = p_state->defarg;
|
||||||
self = p_state->self;
|
self = p_state->self;
|
||||||
|
@ -368,9 +368,9 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
|
||||||
} else {
|
} else {
|
||||||
self = p_instance->owner;
|
self = p_instance->owner;
|
||||||
}
|
}
|
||||||
_class = p_instance->script.ptr();
|
script = p_instance->script.ptr();
|
||||||
} else {
|
} else {
|
||||||
_class = _script;
|
script = _script;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -395,7 +395,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
|
||||||
|
|
||||||
#define GET_VARIANT_PTR(m_v, m_code_ofs) \
|
#define GET_VARIANT_PTR(m_v, m_code_ofs) \
|
||||||
Variant *m_v; \
|
Variant *m_v; \
|
||||||
m_v = _get_variant(_code_ptr[ip + m_code_ofs], p_instance, _class, self, stack, err_text); \
|
m_v = _get_variant(_code_ptr[ip + m_code_ofs], p_instance, script, self, stack, err_text); \
|
||||||
if (unlikely(!m_v)) \
|
if (unlikely(!m_v)) \
|
||||||
OPCODE_BREAK;
|
OPCODE_BREAK;
|
||||||
|
|
||||||
|
@ -404,7 +404,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
|
||||||
#define CHECK_SPACE(m_space)
|
#define CHECK_SPACE(m_space)
|
||||||
#define GET_VARIANT_PTR(m_v, m_code_ofs) \
|
#define GET_VARIANT_PTR(m_v, m_code_ofs) \
|
||||||
Variant *m_v; \
|
Variant *m_v; \
|
||||||
m_v = _get_variant(_code_ptr[ip + m_code_ofs], p_instance, _class, self, stack, err_text);
|
m_v = _get_variant(_code_ptr[ip + m_code_ofs], p_instance, script, self, stack, err_text);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1256,11 +1256,10 @@ 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._class = _class;
|
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.instance_id = (p_instance && p_instance->get_owner()) ? p_instance->get_owner()->get_instance_id() : 0;
|
gdfs->state.instance_id = (p_instance && p_instance->get_owner()) ? p_instance->get_owner()->get_instance_id() : 0;
|
||||||
gdfs->state.script_id = _class->get_instance_id();
|
|
||||||
//gdfs->state.result_pos=ip+ipofs-1;
|
//gdfs->state.result_pos=ip+ipofs-1;
|
||||||
gdfs->state.defarg = defarg;
|
gdfs->state.defarg = defarg;
|
||||||
gdfs->state.instance = p_instance;
|
gdfs->state.instance = p_instance;
|
||||||
|
@ -1549,8 +1548,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
|
||||||
String err_file;
|
String err_file;
|
||||||
if (p_instance)
|
if (p_instance)
|
||||||
err_file = p_instance->script->path;
|
err_file = p_instance->script->path;
|
||||||
else if (_class)
|
else if (script)
|
||||||
err_file = _class->path;
|
err_file = script->path;
|
||||||
if (err_file == "")
|
if (err_file == "")
|
||||||
err_file = "<built-in>";
|
err_file = "<built-in>";
|
||||||
String err_func = name;
|
String err_func = name;
|
||||||
|
@ -1764,17 +1763,14 @@ GDScriptFunction::~GDScriptFunction() {
|
||||||
|
|
||||||
Variant GDScriptFunctionState::_signal_callback(const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
|
Variant GDScriptFunctionState::_signal_callback(const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
|
||||||
|
|
||||||
#ifdef DEBUG_ENABLED
|
|
||||||
if (state.instance_id && !ObjectDB::get_instance(state.instance_id)) {
|
if (state.instance_id && !ObjectDB::get_instance(state.instance_id)) {
|
||||||
|
#ifdef DEBUG_ENABLED
|
||||||
ERR_EXPLAIN("Resumed after yield, but class instance is gone");
|
ERR_EXPLAIN("Resumed after yield, but class instance is gone");
|
||||||
ERR_FAIL_V(Variant());
|
ERR_FAIL_V(Variant());
|
||||||
}
|
#else
|
||||||
|
return Variant();
|
||||||
if (state.script_id && !ObjectDB::get_instance(state.script_id)) {
|
|
||||||
ERR_EXPLAIN("Resumed after yield, but script is gone");
|
|
||||||
ERR_FAIL_V(Variant());
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
Variant arg;
|
Variant arg;
|
||||||
r_error.error = Variant::CallError::CALL_OK;
|
r_error.error = Variant::CallError::CALL_OK;
|
||||||
|
@ -1844,9 +1840,6 @@ bool GDScriptFunctionState::is_valid(bool p_extended_check) const {
|
||||||
//class instance gone?
|
//class instance gone?
|
||||||
if (state.instance_id && !ObjectDB::get_instance(state.instance_id))
|
if (state.instance_id && !ObjectDB::get_instance(state.instance_id))
|
||||||
return false;
|
return false;
|
||||||
//script gone?
|
|
||||||
if (state.script_id && !ObjectDB::get_instance(state.script_id))
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -1855,17 +1848,14 @@ bool GDScriptFunctionState::is_valid(bool p_extended_check) const {
|
||||||
Variant GDScriptFunctionState::resume(const Variant &p_arg) {
|
Variant GDScriptFunctionState::resume(const Variant &p_arg) {
|
||||||
|
|
||||||
ERR_FAIL_COND_V(!function, Variant());
|
ERR_FAIL_COND_V(!function, Variant());
|
||||||
#ifdef DEBUG_ENABLED
|
|
||||||
if (state.instance_id && !ObjectDB::get_instance(state.instance_id)) {
|
if (state.instance_id && !ObjectDB::get_instance(state.instance_id)) {
|
||||||
|
#ifdef DEBUG_ENABLED
|
||||||
ERR_EXPLAIN("Resumed after yield, but class instance is gone");
|
ERR_EXPLAIN("Resumed after yield, but class instance is gone");
|
||||||
ERR_FAIL_V(Variant());
|
ERR_FAIL_V(Variant());
|
||||||
}
|
#else
|
||||||
|
return Variant();
|
||||||
if (state.script_id && !ObjectDB::get_instance(state.script_id)) {
|
|
||||||
ERR_EXPLAIN("Resumed after yield, but script is gone");
|
|
||||||
ERR_FAIL_V(Variant());
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
state.result = p_arg;
|
state.result = p_arg;
|
||||||
Variant::CallError err;
|
Variant::CallError err;
|
||||||
|
|
|
@ -272,15 +272,13 @@ private:
|
||||||
public:
|
public:
|
||||||
struct CallState {
|
struct CallState {
|
||||||
|
|
||||||
ObjectID instance_id; //by debug only
|
ObjectID instance_id;
|
||||||
ObjectID script_id;
|
|
||||||
|
|
||||||
GDScriptInstance *instance;
|
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;
|
||||||
GDScript *_class;
|
Ref<GDScript> script;
|
||||||
int ip;
|
int ip;
|
||||||
int line;
|
int line;
|
||||||
int defarg;
|
int defarg;
|
||||||
|
|
Loading…
Reference in New Issue