summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2020-02-25 13:26:08 +0100
committerGitHub <noreply@github.com>2020-02-25 13:26:08 +0100
commitfe1dfb5fb74f271d1319cd73e34f8bbdc69de20a (patch)
treede928855131994e41d91a6ad56365e6be5a31a93
parent376a8255a9b65b016fcd81634bfd54fb7fa029df (diff)
parenta5505ce64341029dad9ac45f5a4cbc5648ab1a52 (diff)
Merge pull request #36481 from nekomatata/fix-crash-connect-callable
Fixed crash when connecting a signal in GDScript
-rw-r--r--core/object.cpp14
-rw-r--r--core/variant.cpp2
2 files changed, 12 insertions, 4 deletions
diff --git a/core/object.cpp b/core/object.cpp
index a61c4ae392..140ee811fe 100644
--- a/core/object.cpp
+++ b/core/object.cpp
@@ -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);
+ Object *target_object = p_callable.get_object();
+ ERR_FAIL_COND_V(!target_object, ERR_INVALID_PARAMETER);
+
SignalData *s = signal_map.getptr(p_signal);
if (!s) {
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.binds = p_binds;
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) {
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) {
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);
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;
}
}
- Object *object = p_callable.get_object();
- ERR_FAIL_COND(!object);
- object->connections.erase(slot->cE);
+
+ target_object->connections.erase(slot->cE);
s->slot_map.erase(p_callable);
if (s->slot_map.empty() && ClassDB::has_signal(get_class_name(), p_signal)) {
diff --git a/core/variant.cpp b/core/variant.cpp
index 877e188809..1e09df98c7 100644
--- a/core/variant.cpp
+++ b/core/variant.cpp
@@ -1549,6 +1549,8 @@ Variant::operator uint64_t() const {
Variant::operator ObjectID() const {
if (type == INT) {
return ObjectID(_data._int);
+ } else if (type == OBJECT) {
+ return _get_obj().id;
} else {
return ObjectID();
}