Make memnew(RefCounted) return Ref, to force callers to take ownership of it through a reference.

This commit is contained in:
Lukas Tenbrink
2025-10-23 18:21:08 +02:00
parent 456bdea954
commit 05c33acbb1
58 changed files with 174 additions and 196 deletions
+7 -6
View File
@@ -226,16 +226,17 @@ Variant GDScript::_new(const Variant **p_args, int p_argcount, Callable::CallErr
ERR_FAIL_COND_V(_baseptr->native.is_null(), Variant());
if (_baseptr->native.ptr()) {
owner = _baseptr->native->instantiate();
RefCounted *r = Object::cast_to<RefCounted>(owner);
if (r) {
ref = Ref<RefCounted>(r);
}
} else {
owner = memnew(RefCounted); //by default, no base means use reference
ref = memnew(RefCounted); // By default, no base means use reference.
owner = ref.ptr();
}
ERR_FAIL_NULL_V_MSG(owner, Variant(), "Can't inherit from a virtual class.");
RefCounted *r = Object::cast_to<RefCounted>(owner);
if (r) {
ref = Ref<RefCounted>(r);
}
GDScriptInstance *instance = _create_instance(p_args, p_argcount, owner, r_error);
if (!instance) {
if (ref.is_null()) {