From 5e816fd8c8e8c97e22f636573667a99ac705e56c Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 20 Jun 2016 01:15:02 -0300 Subject: [PATCH] Property reporty base type when a function fails, fixes #4581 probably also closes other issues --- core/variant.h | 1 + core/variant_call.cpp | 17 ++++++++++++----- modules/gdscript/gd_function.cpp | 4 ++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/core/variant.h b/core/variant.h index 9c93ecb73b0..87bf20f8ee2 100644 --- a/core/variant.h +++ b/core/variant.h @@ -385,6 +385,7 @@ public: Type expected; }; + void call_ptr(const StringName& p_method,const Variant** p_args,int p_argcount,Variant* r_ret,CallError &r_error); Variant call(const StringName& p_method,const Variant** p_args,int p_argcount,CallError &r_error); Variant call(const StringName& p_method,const Variant& p_arg1=Variant(),const Variant& p_arg2=Variant(),const Variant& p_arg3=Variant(),const Variant& p_arg4=Variant(),const Variant& p_arg5=Variant()); diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 00551385825..29a92febbda 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -937,26 +937,32 @@ _VariantCall::ConstantData* _VariantCall::constant_data=NULL; Variant Variant::call(const StringName& p_method,const Variant** p_args,int p_argcount,CallError &r_error) { Variant ret; + call_ptr(p_method,p_args,p_argcount,&ret,r_error); + return ret; +} + +void Variant::call_ptr(const StringName& p_method,const Variant** p_args,int p_argcount,Variant* r_ret,CallError &r_error) { + Variant ret; if (type==Variant::OBJECT) { //call object Object *obj = _get_obj().obj; if (!obj) { r_error.error=CallError::CALL_ERROR_INSTANCE_IS_NULL; - return ret; + return; } #ifdef DEBUG_ENABLED if (ScriptDebugger::get_singleton() && _get_obj().ref.is_null()) { //only if debugging! if (!ObjectDB::instance_validate(obj)) { r_error.error=CallError::CALL_ERROR_INSTANCE_IS_NULL; - return ret; + return; } } #endif - return _get_obj().obj->call(p_method,p_args,p_argcount,r_error); + ret=_get_obj().obj->call(p_method,p_args,p_argcount,r_error); //else if (type==Variant::METHOD) { @@ -968,14 +974,15 @@ Variant Variant::call(const StringName& p_method,const Variant** p_args,int p_ar #ifdef DEBUG_ENABLED if (!E) { r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD; - return Variant(); + return; } #endif _VariantCall::FuncData& funcdata = E->get(); funcdata.call(ret,*this,p_args,p_argcount,r_error); } - return ret; + if (r_error.error==Variant::CallError::CALL_OK && r_ret) + *r_ret=ret; } #define VCALL(m_type,m_method) _VariantCall::_call_##m_type##_##m_method diff --git a/modules/gdscript/gd_function.cpp b/modules/gdscript/gd_function.cpp index 9d438998cb1..6e52686de49 100644 --- a/modules/gdscript/gd_function.cpp +++ b/modules/gdscript/gd_function.cpp @@ -654,10 +654,10 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a if (call_ret) { GET_VARIANT_PTR(ret,argc); - *ret = base->call(*methodname,(const Variant**)argptrs,argc,err); + base->call_ptr(*methodname,(const Variant**)argptrs,argc,ret,err); } else { - base->call(*methodname,(const Variant**)argptrs,argc,err); + base->call_ptr(*methodname,(const Variant**)argptrs,argc,NULL,err); } #ifdef DEBUG_ENABLED if (GDScriptLanguage::get_singleton()->profiling) {