summaryrefslogtreecommitdiffstats
path: root/core/reference.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/reference.cpp')
-rw-r--r--core/reference.cpp35
1 files changed, 27 insertions, 8 deletions
diff --git a/core/reference.cpp b/core/reference.cpp
index c33a7c683c..6ccc444b93 100644
--- a/core/reference.cpp
+++ b/core/reference.cpp
@@ -30,7 +30,7 @@
#include "reference.h"
-#include "script_language.h"
+#include "core/script_language.h"
bool Reference::init_ref() {
@@ -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;
@@ -120,8 +139,8 @@ void WeakRef::set_ref(const REF &p_ref) {
ref = p_ref.is_valid() ? p_ref->get_instance_id() : 0;
}
-WeakRef::WeakRef() {
- ref = 0;
+WeakRef::WeakRef() :
+ ref(0) {
}
void WeakRef::_bind_methods() {