Merge pull request #36481 from nekomatata/fix-crash-connect-callable
Fixed crash when connecting a signal in GDScript
This commit is contained in:
commit
fe1dfb5fb7
2 changed files with 12 additions and 4 deletions
|
@ -1405,6 +1405,9 @@ Error Object::connect(const StringName &p_signal, const Callable &p_callable, co
|
||||||
|
|
||||||
ERR_FAIL_COND_V(p_callable.is_null(), ERR_INVALID_PARAMETER);
|
ERR_FAIL_COND_V(p_callable.is_null(), ERR_INVALID_PARAMETER);
|
||||||
|
|
||||||
|
Object *target_object = p_callable.get_object();
|
||||||
|
ERR_FAIL_COND_V(!target_object, ERR_INVALID_PARAMETER);
|
||||||
|
|
||||||
SignalData *s = signal_map.getptr(p_signal);
|
SignalData *s = signal_map.getptr(p_signal);
|
||||||
if (!s) {
|
if (!s) {
|
||||||
bool signal_is_valid = ClassDB::has_signal(get_class_name(), p_signal);
|
bool signal_is_valid = ClassDB::has_signal(get_class_name(), p_signal);
|
||||||
|
@ -1449,7 +1452,7 @@ Error Object::connect(const StringName &p_signal, const Callable &p_callable, co
|
||||||
conn.flags = p_flags;
|
conn.flags = p_flags;
|
||||||
conn.binds = p_binds;
|
conn.binds = p_binds;
|
||||||
slot.conn = conn;
|
slot.conn = conn;
|
||||||
slot.cE = p_callable.get_object()->connections.push_back(conn);
|
slot.cE = target_object->connections.push_back(conn);
|
||||||
if (p_flags & CONNECT_REFERENCE_COUNTED) {
|
if (p_flags & CONNECT_REFERENCE_COUNTED) {
|
||||||
slot.reference_count = 1;
|
slot.reference_count = 1;
|
||||||
}
|
}
|
||||||
|
@ -1498,6 +1501,10 @@ void Object::disconnect(const StringName &p_signal, const Callable &p_callable)
|
||||||
void Object::_disconnect(const StringName &p_signal, const Callable &p_callable, bool p_force) {
|
void Object::_disconnect(const StringName &p_signal, const Callable &p_callable, bool p_force) {
|
||||||
|
|
||||||
ERR_FAIL_COND(p_callable.is_null());
|
ERR_FAIL_COND(p_callable.is_null());
|
||||||
|
|
||||||
|
Object *target_object = p_callable.get_object();
|
||||||
|
ERR_FAIL_COND(!target_object);
|
||||||
|
|
||||||
SignalData *s = signal_map.getptr(p_signal);
|
SignalData *s = signal_map.getptr(p_signal);
|
||||||
ERR_FAIL_COND_MSG(!s, vformat("Nonexistent signal '%s' in %s.", p_signal, to_string()));
|
ERR_FAIL_COND_MSG(!s, vformat("Nonexistent signal '%s' in %s.", p_signal, to_string()));
|
||||||
|
|
||||||
|
@ -1511,9 +1518,8 @@ void Object::_disconnect(const StringName &p_signal, const Callable &p_callable,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Object *object = p_callable.get_object();
|
|
||||||
ERR_FAIL_COND(!object);
|
target_object->connections.erase(slot->cE);
|
||||||
object->connections.erase(slot->cE);
|
|
||||||
s->slot_map.erase(p_callable);
|
s->slot_map.erase(p_callable);
|
||||||
|
|
||||||
if (s->slot_map.empty() && ClassDB::has_signal(get_class_name(), p_signal)) {
|
if (s->slot_map.empty() && ClassDB::has_signal(get_class_name(), p_signal)) {
|
||||||
|
|
|
@ -1549,6 +1549,8 @@ Variant::operator uint64_t() const {
|
||||||
Variant::operator ObjectID() const {
|
Variant::operator ObjectID() const {
|
||||||
if (type == INT) {
|
if (type == INT) {
|
||||||
return ObjectID(_data._int);
|
return ObjectID(_data._int);
|
||||||
|
} else if (type == OBJECT) {
|
||||||
|
return _get_obj().id;
|
||||||
} else {
|
} else {
|
||||||
return ObjectID();
|
return ObjectID();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue