diff options
-rw-r--r-- | core/reference.cpp | 3 | ||||
-rw-r--r-- | modules/gdscript/gd_parser.cpp | 3 | ||||
-rw-r--r-- | modules/nativescript/nativescript.cpp | 22 | ||||
-rw-r--r-- | modules/nativescript/nativescript.h | 3 |
4 files changed, 29 insertions, 2 deletions
diff --git a/core/reference.cpp b/core/reference.cpp index c55f8a7fe3..060608eacb 100644 --- a/core/reference.cpp +++ b/core/reference.cpp @@ -74,7 +74,8 @@ bool Reference::unreference() { bool die = refcount.unref(); if (get_script_instance()) { - die = die && get_script_instance()->refcount_decremented(); + bool script_ret = get_script_instance()->refcount_decremented(); + die = die && script_ret; } return die; diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp index ba0413a5a9..36aa249398 100644 --- a/modules/gdscript/gd_parser.cpp +++ b/modules/gdscript/gd_parser.cpp @@ -314,9 +314,10 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool path += String(tokenizer->get_token_literal()); tokenizer->advance(); need_identifier = false; + } else { + done = true; } - done = true; break; } } diff --git a/modules/nativescript/nativescript.cpp b/modules/nativescript/nativescript.cpp index f3db33cce2..271f5bde1c 100644 --- a/modules/nativescript/nativescript.cpp +++ b/modules/nativescript/nativescript.cpp @@ -628,6 +628,28 @@ void NativeScriptInstance::notification(int p_notification) { call_multilevel("_notification", args, 1); } +void NativeScriptInstance::refcount_incremented() { + Variant::CallError err; + call("_refcount_incremented", NULL, 0, err); + if (err.error != Variant::CallError::CALL_OK && err.error != Variant::CallError::CALL_ERROR_INVALID_METHOD) { + ERR_PRINT("Failed to invoke _refcount_incremented - should not happen"); + } +} + +bool NativeScriptInstance::refcount_decremented() { + Variant::CallError err; + Variant ret = call("_refcount_decremented", NULL, 0, err); + if (err.error != Variant::CallError::CALL_OK && err.error != Variant::CallError::CALL_ERROR_INVALID_METHOD) { + ERR_PRINT("Failed to invoke _refcount_decremented - should not happen"); + return true; // assume we can destroy the object + } + if (err.error == Variant::CallError::CALL_ERROR_INVALID_METHOD) { + // the method does not exist, default is true + return true; + } + return ret; +} + Ref<Script> NativeScriptInstance::get_script() const { return script; } diff --git a/modules/nativescript/nativescript.h b/modules/nativescript/nativescript.h index cf3a64e9b8..05e2d361d3 100644 --- a/modules/nativescript/nativescript.h +++ b/modules/nativescript/nativescript.h @@ -185,6 +185,9 @@ public: virtual void call_multilevel(const StringName &p_method, const Variant **p_args, int p_argcount); virtual void call_multilevel_reversed(const StringName &p_method, const Variant **p_args, int p_argcount); + virtual void refcount_incremented(); + virtual bool refcount_decremented(); + ~NativeScriptInstance(); }; |