summaryrefslogtreecommitdiff
path: root/modules/gdscript
diff options
context:
space:
mode:
authorPedro J. Estébanez <pedrojrulez@gmail.com>2023-02-03 11:42:51 +0100
committerPedro J. Estébanez <pedrojrulez@gmail.com>2023-02-03 17:48:41 +0100
commit0bcc7bb5c77fffba05476d38e16ea34c06184f29 (patch)
treee09825de0b20b4479ed1f2d9525b943fedfab616 /modules/gdscript
parent1ed549e64b141e068bfe1a59bf65e943cde3fc6c (diff)
Avoid losing references to objects in the native-scripting boundary
Diffstat (limited to 'modules/gdscript')
-rw-r--r--modules/gdscript/gdscript_vm.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/modules/gdscript/gdscript_vm.cpp b/modules/gdscript/gdscript_vm.cpp
index b99f5d2685..1ab8109dd4 100644
--- a/modules/gdscript/gdscript_vm.cpp
+++ b/modules/gdscript/gdscript_vm.cpp
@@ -1969,7 +1969,13 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
VariantInternal::initialize(ret, Variant::OBJECT);
Object **ret_opaque = VariantInternal::get_object(ret);
method->ptrcall(base_obj, argptrs, ret_opaque);
- VariantInternal::update_object_id(ret);
+ if (method->is_return_type_raw_object_ptr()) {
+ // The Variant has to participate in the ref count since the method returns a raw Object *.
+ VariantInternal::object_assign(ret, *ret_opaque);
+ } else {
+ // The method, in case it returns something, returns an already encapsulated object.
+ VariantInternal::update_object_id(ret);
+ }
#ifdef DEBUG_ENABLED
if (GDScriptLanguage::get_singleton()->profiling) {