diff --git a/core/extension/gdextension_interface.cpp b/core/extension/gdextension_interface.cpp index a5a0fc906aa..0ebe86d0a71 100644 --- a/core/extension/gdextension_interface.cpp +++ b/core/extension/gdextension_interface.cpp @@ -1299,7 +1299,7 @@ static void gdextension_object_call_script_method(GDExtensionObjectPtr p_object, const StringName method = *reinterpret_cast(p_method); const Variant **args = (const Variant **)p_args; - Callable::CallError error; + Callable::CallError error; // TODO: Check `error`? memnew_placement(r_return, Variant); *(Variant *)r_return = o->callp(method, args, p_argument_count, error); diff --git a/core/object/class_db.cpp b/core/object/class_db.cpp index c929b29ee92..b81130f43e7 100644 --- a/core/object/class_db.cpp +++ b/core/object/class_db.cpp @@ -1648,14 +1648,16 @@ bool ClassDB::get_property(Object *p_object, const StringName &p_property, Varia Variant index = psg->index; const Variant *arg[1] = { &index }; Callable::CallError ce; - r_value = p_object->callp(psg->getter, arg, 1, ce); + const Variant value = p_object->callp(psg->getter, arg, 1, ce); + r_value = (ce.error == Callable::CallError::CALL_OK) ? value : Variant(); } else { Callable::CallError ce; if (psg->_getptr) { r_value = psg->_getptr->call(p_object, nullptr, 0, ce); } else { - r_value = p_object->callp(psg->getter, nullptr, 0, ce); + const Variant value = p_object->callp(psg->getter, nullptr, 0, ce); + r_value = (ce.error == Callable::CallError::CALL_OK) ? value : Variant(); } } return true; diff --git a/core/object/object.cpp b/core/object/object.cpp index da2a6e7587f..8b3ab402710 100644 --- a/core/object/object.cpp +++ b/core/object/object.cpp @@ -746,7 +746,7 @@ Variant Object::callv(const StringName &p_method, const Array &p_args) { } Callable::CallError ce; - Variant ret = callp(p_method, argptrs, p_args.size(), ce); + const Variant ret = callp(p_method, argptrs, p_args.size(), ce); if (ce.error != Callable::CallError::CALL_OK) { ERR_FAIL_V_MSG(Variant(), "Error calling method from 'callv': " + Variant::get_call_error_text(this, p_method, argptrs, p_args.size(), ce) + "."); } @@ -787,7 +787,7 @@ Variant Object::callp(const StringName &p_method, const Variant **p_args, int p_ if (script_instance) { ret = script_instance->callp(p_method, p_args, p_argcount, r_error); - //force jumptable + // Force jump table. switch (r_error.error) { case Callable::CallError::CALL_OK: return ret; diff --git a/core/object/object.h b/core/object/object.h index 4752e72d672..bc3f663baf9 100644 --- a/core/object/object.h +++ b/core/object/object.h @@ -867,7 +867,8 @@ public: argptrs[i] = &args[i]; } Callable::CallError cerr; - return callp(p_method, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args), cerr); + const Variant ret = callp(p_method, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args), cerr); + return (cerr.error == Callable::CallError::CALL_OK) ? ret : Variant(); } void notification(int p_notification, bool p_reversed = false); diff --git a/core/variant/callable.cpp b/core/variant/callable.cpp index 667aae879ca..9dff5c1e910 100644 --- a/core/variant/callable.cpp +++ b/core/variant/callable.cpp @@ -112,7 +112,7 @@ Error Callable::rpcp(int p_id, const Variant **p_arguments, int p_argcount, Call argptrs[i + 2] = p_arguments[i]; } - CallError tmp; + CallError tmp; // TODO: Check `tmp`? Error err = (Error)obj->callp(SNAME("rpc_id"), argptrs, argcount, tmp).operator int64_t(); r_call_error.error = Callable::CallError::CALL_OK; diff --git a/core/variant/variant.cpp b/core/variant/variant.cpp index 24b30112bd7..186643b024a 100644 --- a/core/variant/variant.cpp +++ b/core/variant/variant.cpp @@ -2113,7 +2113,7 @@ Variant::operator ::RID() const { } #endif Callable::CallError ce; - Variant ret = _get_obj().obj->callp(CoreStringName(get_rid), nullptr, 0, ce); + const Variant ret = _get_obj().obj->callp(CoreStringName(get_rid), nullptr, 0, ce); if (ce.error == Callable::CallError::CALL_OK && ret.get_type() == Variant::RID) { return ret; } diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index 36c5ad09377..e3f2a610909 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -954,7 +954,8 @@ bool GDScript::_get(const StringName &p_name, Variant &r_ret) const { if (E) { if (likely(top->valid) && E->value.getter) { Callable::CallError ce; - r_ret = const_cast(this)->callp(E->value.getter, nullptr, 0, ce); + const Variant ret = const_cast(this)->callp(E->value.getter, nullptr, 0, ce); + r_ret = (ce.error == Callable::CallError::CALL_OK) ? ret : Variant(); return true; } r_ret = top->static_variables[E->value.index]; @@ -1727,10 +1728,9 @@ bool GDScriptInstance::get(const StringName &p_name, Variant &r_ret) const { if (E) { if (likely(script->valid) && E->value.getter) { Callable::CallError err; - r_ret = const_cast(this)->callp(E->value.getter, nullptr, 0, err); - if (err.error == Callable::CallError::CALL_OK) { - return true; - } + const Variant ret = const_cast(this)->callp(E->value.getter, nullptr, 0, err); + r_ret = (err.error == Callable::CallError::CALL_OK) ? ret : Variant(); + return true; } r_ret = members[E->value.index]; return true; @@ -1752,7 +1752,8 @@ bool GDScriptInstance::get(const StringName &p_name, Variant &r_ret) const { if (E) { if (likely(sptr->valid) && E->value.getter) { Callable::CallError ce; - r_ret = const_cast(sptr)->callp(E->value.getter, nullptr, 0, ce); + const Variant ret = const_cast(sptr)->callp(E->value.getter, nullptr, 0, ce); + r_ret = (ce.error == Callable::CallError::CALL_OK) ? ret : Variant(); return true; } r_ret = sptr->static_variables[E->value.index];