diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/reference.cpp | 13 | ||||
-rw-r--r-- | core/reference.h | 2 | ||||
-rw-r--r-- | core/variant.cpp | 4 |
3 files changed, 11 insertions, 8 deletions
diff --git a/core/reference.cpp b/core/reference.cpp index bb70628cbe..7f93922d22 100644 --- a/core/reference.cpp +++ b/core/reference.cpp @@ -33,7 +33,7 @@ bool Reference::init_ref() { - if (refcount.ref()) { + if (reference()) { // this may fail in the scenario of two threads assigning the pointer for the FIRST TIME // at the same time, which is never likely to happen (would be crazy to do) @@ -41,7 +41,7 @@ bool Reference::init_ref() { if (refcount_init.get() > 0) { refcount_init.unref(); - refcount.unref(); // first referencing is already 1, so compensate for the ref above + unreference(); // first referencing is already 1, so compensate for the ref above } return true; @@ -62,13 +62,16 @@ int Reference::reference_get_count() const { return refcount.get(); } -void Reference::reference() { +bool Reference::reference() { + bool success = refcount.ref(); - refcount.ref(); - if (get_script_instance()) { + if (success && get_script_instance()) { get_script_instance()->refcount_incremented(); } + + return success; } + bool Reference::unreference() { bool die = refcount.unref(); diff --git a/core/reference.h b/core/reference.h index ca3ae60418..bafc164276 100644 --- a/core/reference.h +++ b/core/reference.h @@ -51,7 +51,7 @@ protected: public: _FORCE_INLINE_ bool is_referenced() const { return refcount_init.get() < 1; } bool init_ref(); - void reference(); + bool reference(); // returns false if refcount is at zero and didn't get increased bool unreference(); int reference_get_count() const; diff --git a/core/variant.cpp b/core/variant.cpp index 74f6b6a711..10d86152ee 100644 --- a/core/variant.cpp +++ b/core/variant.cpp @@ -2259,8 +2259,8 @@ Variant::Variant(const RefPtr &p_resource) { type = OBJECT; memnew_placement(_data._mem, ObjData); - REF ref = p_resource; - _get_obj().obj = ref.ptr(); + REF *ref = reinterpret_cast<REF *>(p_resource.get_data()); + _get_obj().obj = ref->ptr(); _get_obj().ref = p_resource; } |