You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-10 13:00:37 +00:00
Merge pull request #9882 from endragor/nativescript-refcount
Forward refcount changes to NativeScriptInstance
This commit is contained in:
@@ -74,7 +74,8 @@ bool Reference::unreference() {
|
|||||||
bool die = refcount.unref();
|
bool die = refcount.unref();
|
||||||
|
|
||||||
if (get_script_instance()) {
|
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;
|
return die;
|
||||||
|
|||||||
@@ -628,6 +628,28 @@ void NativeScriptInstance::notification(int p_notification) {
|
|||||||
call_multilevel("_notification", args, 1);
|
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 {
|
Ref<Script> NativeScriptInstance::get_script() const {
|
||||||
return script;
|
return script;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -185,6 +185,9 @@ public:
|
|||||||
virtual void call_multilevel(const StringName &p_method, const Variant **p_args, int p_argcount);
|
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 call_multilevel_reversed(const StringName &p_method, const Variant **p_args, int p_argcount);
|
||||||
|
|
||||||
|
virtual void refcount_incremented();
|
||||||
|
virtual bool refcount_decremented();
|
||||||
|
|
||||||
~NativeScriptInstance();
|
~NativeScriptInstance();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user