Promote object validity checks to release builds
Extra: - Optimized the debug-only check about why the object is null to determine if it's because it has been deleted (the RC is enough; no need to check the ObjectDB). - Because of the previous point. the debugger being attached is not required anymore for giving the "Object was deleted" error; from now, it only matters that it's a debug build. - `is_instance_valid()` is now trustworthy. It will return `true` if, and only if, the last object assigned to a `Variant` is still alive (and not if a new object happened to be created at the same memory address of the old one). - Replacements of `instance_validate()` are used where possible `Variant::is_invalid_object()` is introduced to help with that. (GDScript's `is_instance_valid()` is good.)
This commit is contained in:
@ -41,9 +41,7 @@
|
||||
#include "core/variant.h"
|
||||
#include "core/vmap.h"
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
#include <atomic> // For ObjectRC*
|
||||
#endif
|
||||
#include <atomic>
|
||||
|
||||
#define VARIANT_ARG_LIST 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()
|
||||
#define VARIANT_ARG_PASS p_arg1, p_arg2, p_arg3, p_arg4, p_arg5
|
||||
@ -476,9 +474,7 @@ private:
|
||||
int _predelete_ok;
|
||||
Set<Object *> change_receptors;
|
||||
ObjectID _instance_id;
|
||||
#ifdef DEBUG_ENABLED
|
||||
std::atomic<ObjectRC *> _rc;
|
||||
#endif
|
||||
bool _predelete();
|
||||
void _postinitialize();
|
||||
bool _can_translate;
|
||||
@ -590,9 +586,7 @@ public:
|
||||
return &ptr;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
ObjectRC *_use_rc();
|
||||
#endif
|
||||
|
||||
bool _is_gpl_reversed() const { return false; }
|
||||
|
||||
@ -798,6 +792,7 @@ public:
|
||||
static void debug_objects(DebugFunc p_func);
|
||||
static int get_object_count();
|
||||
|
||||
// This one may give false positives because a new object may be allocated at the same memory of a previously freed one
|
||||
_FORCE_INLINE_ static bool instance_validate(Object *p_ptr) {
|
||||
rw_lock.read_lock();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user