Avoid losing references to objects in the native-scripting boundary

This commit is contained in:
Pedro J. Estébanez 2023-02-03 11:42:51 +01:00
parent 1ed549e64b
commit 0bcc7bb5c7
3 changed files with 40 additions and 1 deletions

View file

@ -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) {