diff options
| author | Juan Linietsky <reduzio@gmail.com> | 2018-08-25 11:01:55 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-08-25 11:01:55 -0300 |
| commit | 8c435a343e9739f30cb2e347df95835c91c1ff1a (patch) | |
| tree | fe53040862deb5bf46d92e1e002086914ff8d80a /core/reference.cpp | |
| parent | 7c5883add0b2534bfc901c538381a7b3cba19966 (diff) | |
| parent | 908a30964a66884f0264021818531cc89c8d2b80 (diff) | |
| download | redot-engine-8c435a343e9739f30cb2e347df95835c91c1ff1a.tar.gz | |
Merge pull request #16927 from neikeq/rework-refcount-notify
Notify instance binding data api of refcount increment/decrement
Diffstat (limited to 'core/reference.cpp')
| -rw-r--r-- | core/reference.cpp | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/core/reference.cpp b/core/reference.cpp index c33a7c683c..6e1520d81d 100644 --- a/core/reference.cpp +++ b/core/reference.cpp @@ -66,8 +66,17 @@ int Reference::reference_get_count() const { bool Reference::reference() { bool success = refcount.ref(); - if (success && get_script_instance()) { - get_script_instance()->refcount_incremented(); + if (success && refcount.get() <= 2 /* higher is not relevant */) { + if (get_script_instance()) { + get_script_instance()->refcount_incremented(); + } + if (instance_binding_count > 0) { + for (int i = 0; i < MAX_SCRIPT_INSTANCE_BINDINGS; i++) { + if (_script_instance_bindings[i]) { + ScriptServer::get_language(i)->refcount_incremented_instance_binding(this); + } + } + } } return success; @@ -77,9 +86,19 @@ bool Reference::unreference() { bool die = refcount.unref(); - if (get_script_instance()) { - bool script_ret = get_script_instance()->refcount_decremented(); - die = die && script_ret; + if (refcount.get() <= 1 /* higher is not relevant */) { + if (get_script_instance()) { + bool script_ret = get_script_instance()->refcount_decremented(); + die = die && script_ret; + } + if (instance_binding_count > 0) { + for (int i = 0; i < MAX_SCRIPT_INSTANCE_BINDINGS; i++) { + if (_script_instance_bindings[i]) { + bool script_ret = ScriptServer::get_language(i)->refcount_decremented_instance_binding(this); + die = die && script_ret; + } + } + } } return die; |
