From c2e63fd27a2112fd2562c7307d15a7516adb52fd Mon Sep 17 00:00:00 2001 From: Giacom Date: Mon, 8 Apr 2019 02:52:21 +0100 Subject: [PATCH] Fixes being unable to use the Quat(Vector3) constructor The Quat(Vector3) constructor, to initialise a Quat by a euler angle, was impossible because Variant::construct would only check for constructors with greater than 1 arguments. I changed it to greater than or equal to 1 and moved it to the bottom of the priority list so it did not overshadow the other checks that checked for arguments equal to 1 for simple copy constructors. --- core/variant_call.cpp | 49 +++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 9ef7b7e7e6a..ca8b4e119ae 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -1126,31 +1126,6 @@ Variant Variant::construct(const Variant::Type p_type, const Variant **p_args, i default: return Variant(); } - } else if (p_argcount > 1) { - - _VariantCall::ConstructFunc &c = _VariantCall::construct_funcs[p_type]; - - for (List<_VariantCall::ConstructData>::Element *E = c.constructors.front(); E; E = E->next()) { - const _VariantCall::ConstructData &cd = E->get(); - - if (cd.arg_count != p_argcount) - continue; - - //validate parameters - for (int i = 0; i < cd.arg_count; i++) { - if (!Variant::can_convert(p_args[i]->type, cd.arg_types[i])) { - r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; //no such constructor - r_error.argument = i; - r_error.expected = cd.arg_types[i]; - return Variant(); - } - } - - Variant v; - cd.func(v, p_args); - return v; - } - } else if (p_argcount == 1 && p_args[0]->type == p_type) { return *p_args[0]; //copy construct } else if (p_argcount == 1 && (!p_strict || Variant::can_convert(p_args[0]->type, p_type))) { @@ -1207,6 +1182,30 @@ Variant Variant::construct(const Variant::Type p_type, const Variant **p_args, i case POOL_COLOR_ARRAY: return (PoolColorArray(*p_args[0])); default: return Variant(); } + } else if (p_argcount >= 1) { + + _VariantCall::ConstructFunc &c = _VariantCall::construct_funcs[p_type]; + + for (List<_VariantCall::ConstructData>::Element *E = c.constructors.front(); E; E = E->next()) { + const _VariantCall::ConstructData &cd = E->get(); + + if (cd.arg_count != p_argcount) + continue; + + //validate parameters + for (int i = 0; i < cd.arg_count; i++) { + if (!Variant::can_convert(p_args[i]->type, cd.arg_types[i])) { + r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; //no such constructor + r_error.argument = i; + r_error.expected = cd.arg_types[i]; + return Variant(); + } + } + + Variant v; + cd.func(v, p_args); + return v; + } } r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; //no such constructor return Variant();