diff --git a/core/object/object.cpp b/core/object/object.cpp index d6b7d7a7fe06..61c36678fa1a 100644 --- a/core/object/object.cpp +++ b/core/object/object.cpp @@ -45,14 +45,18 @@ #ifdef DEBUG_ENABLED struct _ObjectDebugLock { - Object *obj; + Variant obj; _ObjectDebugLock(Object *p_obj) { obj = p_obj; - obj->_lock_index.ref(); + p_obj->_lock_index.ref(); } ~_ObjectDebugLock() { - obj->_lock_index.unref(); + bool freed = false; + Object *obj_ptr = obj.get_validated_object_with_check(freed); + if (obj_ptr) { + obj_ptr->_lock_index.unref(); + } } };