diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-10-02 15:00:47 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-10-02 15:00:47 +0200 |
commit | 9ce149c7a3cd940d734ec50a4ce78d246d0012ef (patch) | |
tree | 2cd3ab2c1dee386225c8937fe50df6ef46010952 /core/variant/variant.h | |
parent | 7f1f9799c5955af4e29ecb7d4d3d765ad36f5beb (diff) | |
parent | cee0e6667a2583a128ab3de33ab43f06222c4ca9 (diff) | |
download | redot-engine-9ce149c7a3cd940d734ec50a4ce78d246d0012ef.tar.gz |
Merge pull request #93299 from rune-scape/fix-ref
Fix RefCounted releasing early and not clearing reference
Diffstat (limited to 'core/variant/variant.h')
-rw-r--r-- | core/variant/variant.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/core/variant/variant.h b/core/variant/variant.h index d4e4b330cd..c76b849abd 100644 --- a/core/variant/variant.h +++ b/core/variant/variant.h @@ -62,6 +62,10 @@ #include "core/variant/dictionary.h" class Object; +class RefCounted; + +template <typename T> +class Ref; struct PropertyInfo; struct MethodInfo; @@ -175,6 +179,20 @@ private: struct ObjData { ObjectID id; Object *obj = nullptr; + + void ref(const ObjData &p_from); + void ref_pointer(Object *p_object); + void ref_pointer(RefCounted *p_object); + void unref(); + + template <typename T> + _ALWAYS_INLINE_ void ref(const Ref<T> &p_from) { + if (p_from.is_valid()) { + ref(ObjData{ p_from->get_instance_id(), p_from.ptr() }); + } else { + unref(); + } + } }; /* array helpers */ |