summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2017-08-05 19:48:29 -0300
committerJuan Linietsky <reduzio@gmail.com>2017-08-05 19:50:53 -0300
commita3a7fb83e645112eb2b7f6620cda9fbaf434311a (patch)
tree89d5fb27992a04044751cda28d3f30ae45bc63a3 /core
parent435bedd9ef58817926bb0e7df9586e1d137b761b (diff)
Made bool constructor explicit in Variant to avoid bugs, fixes #7843
Diffstat (limited to 'core')
-rw-r--r--core/object.cpp19
-rw-r--r--core/object.h4
-rw-r--r--core/resource.cpp1
-rw-r--r--core/variant.h4
4 files changed, 18 insertions, 10 deletions
diff --git a/core/object.cpp b/core/object.cpp
index 316c624268..525eb2ff38 100644
--- a/core/object.cpp
+++ b/core/object.cpp
@@ -1182,10 +1182,10 @@ Variant Object::_emit_signal(const Variant **p_args, int p_argcount, Variant::Ca
return Variant();
}
-void Object::emit_signal(const StringName &p_name, const Variant **p_args, int p_argcount) {
+Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int p_argcount) {
if (_block_signals)
- return; //no emit, signals blocked
+ return ERR_CANT_AQUIRE_RESOURCE; //no emit, signals blocked
Signal *s = signal_map.getptr(p_name);
if (!s) {
@@ -1194,11 +1194,11 @@ void Object::emit_signal(const StringName &p_name, const Variant **p_args, int p
//check in script
if (!signal_is_valid && !script.is_null() && !Ref<Script>(script)->has_script_signal(p_name)) {
ERR_EXPLAIN("Can't emit non-existing signal " + String("\"") + p_name + "\".");
- ERR_FAIL();
+ ERR_FAIL_V(ERR_UNAVAILABLE);
}
#endif
//not connected? just return
- return;
+ return ERR_UNAVAILABLE;
}
List<_ObjectSignalDisconnectData> disconnect_data;
@@ -1214,6 +1214,8 @@ void Object::emit_signal(const StringName &p_name, const Variant **p_args, int p
Vector<const Variant *> bind_mem;
+ Error err = OK;
+
for (int i = 0; i < ssize; i++) {
const Connection &c = slot_map.getv(i).conn;
@@ -1249,12 +1251,14 @@ void Object::emit_signal(const StringName &p_name, const Variant **p_args, int p
} else {
Variant::CallError ce;
target->call(c.method, args, argc, ce);
+
if (ce.error != Variant::CallError::CALL_OK) {
if (ce.error == Variant::CallError::CALL_ERROR_INVALID_METHOD && !ClassDB::class_exists(target->get_class_name())) {
//most likely object is not initialized yet, do not throw error.
} else {
ERR_PRINTS("Error calling method from signal '" + String(p_name) + "': " + Variant::get_call_error_text(target, c.method, args, argc, ce));
+ err = ERR_METHOD_NOT_FOUND;
}
}
}
@@ -1274,21 +1278,24 @@ void Object::emit_signal(const StringName &p_name, const Variant **p_args, int p
disconnect(dd.signal, dd.target, dd.method);
disconnect_data.pop_front();
}
+
+ return err;
}
-void Object::emit_signal(const StringName &p_name, VARIANT_ARG_DECLARE) {
+Error Object::emit_signal(const StringName &p_name, VARIANT_ARG_DECLARE) {
VARIANT_ARGPTRS;
int argc = 0;
for (int i = 0; i < VARIANT_ARG_MAX; i++) {
+
if (argptr[i]->get_type() == Variant::NIL)
break;
argc++;
}
- emit_signal(p_name, argptr, argc);
+ return emit_signal(p_name, argptr, argc);
}
void Object::_add_user_signal(const String &p_name, const Array &p_args) {
diff --git a/core/object.h b/core/object.h
index 148a73fbc4..ca2090094e 100644
--- a/core/object.h
+++ b/core/object.h
@@ -654,8 +654,8 @@ public:
void set_script_and_instance(const RefPtr &p_script, ScriptInstance *p_instance); //some script languages can't control instance creation, so this function eases the process
void add_user_signal(const MethodInfo &p_signal);
- void emit_signal(const StringName &p_name, VARIANT_ARG_LIST);
- void emit_signal(const StringName &p_name, const Variant **p_args, int p_argcount);
+ Error emit_signal(const StringName &p_name, VARIANT_ARG_LIST);
+ Error emit_signal(const StringName &p_name, const Variant **p_args, int p_argcount);
void get_signal_list(List<MethodInfo> *p_signals) const;
void get_signal_connection_list(const StringName &p_signal, List<Connection> *p_connections) const;
void get_all_signal_connections(List<Connection> *p_connections) const;
diff --git a/core/resource.cpp b/core/resource.cpp
index 5625784396..86069bf2e9 100644
--- a/core/resource.cpp
+++ b/core/resource.cpp
@@ -32,6 +32,7 @@
#include "core_string_names.h"
#include "io/resource_loader.h"
#include "os/file_access.h"
+#include "scene/main/node.h" //only so casting works
#include "script_language.h"
#include <stdio.h>
diff --git a/core/variant.h b/core/variant.h
index 583a0d09a0..4d137efac2 100644
--- a/core/variant.h
+++ b/core/variant.h
@@ -42,8 +42,8 @@
#include "io/ip_address.h"
#include "math_2d.h"
#include "matrix3.h"
-#include "os/power.h"
#include "node_path.h"
+#include "os/power.h"
#include "plane.h"
#include "quat.h"
#include "rect3.h"
@@ -239,7 +239,7 @@ public:
operator IP_Address() const;
- Variant(bool p_bool);
+ explicit Variant(bool p_bool);
Variant(signed int p_int); // real one
Variant(unsigned int p_int);
#ifdef NEED_LONG_INT