From 9f33134c93ecbadda70e8eefc50563e29b2eb7f2 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sat, 5 Apr 2014 12:39:30 -0300 Subject: =?UTF-8?q?-Support=20for=20changing=20fonts=20-Detect=20when=20fr?= =?UTF-8?q?ee()=20might=20crash=20the=20project=20and=20throw=20error=20-f?= =?UTF-8?q?ixed=202D=20Bounce=20in=20physics=20(3d=20still=20broken)=20-re?= =?UTF-8?q?named=20=E2=80=9Con=5Ftop=E2=80=9D=20property=20to=20=E2=80=9Cb?= =?UTF-8?q?ehind=5Fparent=E2=80=9D,=20which=20makes=20more=20sense,=20old?= =?UTF-8?q?=20on=5Ftop=20remains=20there=20for=20compatibility=20but=20is?= =?UTF-8?q?=20invisible.=20-large=20amount=20of=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/object.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) (limited to 'core/object.cpp') diff --git a/core/object.cpp b/core/object.cpp index 692010b1b7..b40f4ec151 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -33,6 +33,30 @@ #include "message_queue.h" #include "core_string_names.h" #include "translation.h" + +#ifdef DEBUG_ENABLED + +struct _ObjectDebugLock { + + Object *obj; + + _ObjectDebugLock(Object *p_obj) { + obj=p_obj; + obj->_lock_index.ref(); + } + ~_ObjectDebugLock() { + obj->_lock_index.unref(); + } +}; + +#define OBJ_DEBUG_LOCK _ObjectDebugLock _debug_lock(this); + +#else + +#define OBJ_DEBUG_LOCK + +#endif + Array convert_property_list(const List * p_list) { Array va; @@ -562,13 +586,22 @@ void Object::call_multilevel(const StringName& p_method,const Variant** p_args,i ERR_FAIL(); return; } + + + if (_lock_index.get()>1) { + ERR_EXPLAIN("Object is locked and can't be freed."); + ERR_FAIL(); + return; + } #endif + //must be here, must be before everything, memdelete(this); return; } //Variant ret; + OBJ_DEBUG_LOCK Variant::CallError error; @@ -594,6 +627,7 @@ void Object::call_multilevel_reversed(const StringName& p_method,const Variant** MethodBind *method=ObjectTypeDB::get_method(get_type_name(),p_method); Variant::CallError error; + OBJ_DEBUG_LOCK if (method) { @@ -813,6 +847,15 @@ Variant Object::call(const StringName& p_method,const Variant** p_args,int p_arg ERR_EXPLAIN("Can't 'free' a reference."); ERR_FAIL_V(Variant()); } + + if (_lock_index.get()>1) { + r_error.argument=0; + r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD; + ERR_EXPLAIN("Object is locked and can't be freed."); + ERR_FAIL_V(Variant()); + + } + #endif //must be here, must be before everything, memdelete(this); @@ -821,7 +864,7 @@ Variant Object::call(const StringName& p_method,const Variant** p_args,int p_arg } Variant ret; - + OBJ_DEBUG_LOCK if (script_instance) { ret = script_instance->call(p_method,p_args,p_argcount,r_error); //force jumptable @@ -902,7 +945,7 @@ void Object::set_script(const RefPtr& p_script) { Ref