Merge pull request #72654 from RandomShaper/ptrcall_ret_raw_obj

Avoid losing references to objects in the native-scripting boundary
This commit is contained in:
Rémi Verschelde 2023-02-11 15:35:01 +01:00
commit 532381562e
No known key found for this signature in database
GPG key ID: C3336907360768E1
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) {