From 6141ce2cb8ae54965190257a1ffd6a6abd02aaea Mon Sep 17 00:00:00 2001 From: Brian Semrau Date: Mon, 27 Sep 2021 12:23:57 -0400 Subject: [PATCH] GDScript Don't double-reference Refs returned from native function --- core/variant/variant_internal.h | 7 +++++++ modules/gdscript/gdscript_vm.cpp | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/core/variant/variant_internal.h b/core/variant/variant_internal.h index 40c8a1bfde0..ad095c27e7a 100644 --- a/core/variant/variant_internal.h +++ b/core/variant/variant_internal.h @@ -300,6 +300,13 @@ public: v->_get_obj().id = ObjectID(); } + static void update_object_id(Variant *v) { + const Object *o = v->_get_obj().obj; + if (o) { + v->_get_obj().id = o->get_instance_id(); + } + } + _FORCE_INLINE_ static void *get_opaque_pointer(Variant *v) { switch (v->type) { case Variant::NIL: diff --git a/modules/gdscript/gdscript_vm.cpp b/modules/gdscript/gdscript_vm.cpp index 9ea9fc61def..a6ec76f47f4 100644 --- a/modules/gdscript/gdscript_vm.cpp +++ b/modules/gdscript/gdscript_vm.cpp @@ -1814,7 +1814,7 @@ 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::object_assign(ret, *ret_opaque); // Set so ID is correct too. + VariantInternal::update_object_id(ret); #ifdef DEBUG_ENABLED if (GDScriptLanguage::get_singleton()->profiling) {