diff options
author | Thomas Herzog <thomas.herzog@mail.com> | 2017-09-14 21:21:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-14 21:21:50 +0200 |
commit | 5636ac526e1d9b211700ec2386c2a01c2419d1f7 (patch) | |
tree | 2e0d5c7c4ca65fbe857e1e8586314adb1d2c3fe5 /core/reference.cpp | |
parent | 35ed1eef2a6a00087799ded7e10ce94ed4d8b373 (diff) | |
parent | f08bc0df7c16a6d12292628ec8cc2e015047c450 (diff) |
Merge pull request #11237 from endragor/gdnative-variant-ref
Construct Variants from Reference properly in GDNative
Diffstat (limited to 'core/reference.cpp')
-rw-r--r-- | core/reference.cpp | 13 |
1 files changed, 8 insertions, 5 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(); |