Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Fix Variant::construct of Object #90134

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion core/variant/variant_construct.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,14 @@ class VariantConstructor {
class VariantConstructorObject {
public:
static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) {
VariantInternal::clear(&r_ret);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving this below matches the rest of the cases, where errors mean we don't touch it, can move it back above if desired, but take VariantConstructorNilObject for example

if (p_args[0]->get_type() == Variant::NIL) {
VariantInternal::clear(&r_ret);
VariantTypeChanger<Object *>::change(&r_ret);
VariantInternal::object_assign_null(&r_ret);
AThousandShips marked this conversation as resolved.
Show resolved Hide resolved
r_error.error = Callable::CallError::CALL_OK;
} else if (p_args[0]->get_type() == Variant::OBJECT) {
VariantInternal::clear(&r_ret);
VariantTypeChanger<Object *>::change(&r_ret);
VariantInternal::object_assign(&r_ret, p_args[0]);
r_error.error = Callable::CallError::CALL_OK;
} else {
Expand All @@ -169,6 +172,7 @@ class VariantConstructorObject {

static inline void validated_construct(Variant *r_ret, const Variant **p_args) {
VariantInternal::clear(r_ret);
VariantTypeChanger<Object *>::change(r_ret);
VariantInternal::object_assign(r_ret, p_args[0]);
}
static void ptr_construct(void *base, const void **p_args) {
Expand Down Expand Up @@ -198,11 +202,13 @@ class VariantConstructorNilObject {
}

VariantInternal::clear(&r_ret);
VariantTypeChanger<Object *>::change(&r_ret);
VariantInternal::object_assign_null(&r_ret);
AThousandShips marked this conversation as resolved.
Show resolved Hide resolved
}

static inline void validated_construct(Variant *r_ret, const Variant **p_args) {
VariantInternal::clear(r_ret);
VariantTypeChanger<Object *>::change(r_ret);
VariantInternal::object_assign_null(r_ret);
}
static void ptr_construct(void *base, const void **p_args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# https://github.com/godotengine/godot/issues/90086

class MyObj:
var obj: WeakRef

func test():
var obj_1 = MyObj.new()
var obj_2 = MyObj.new()
obj_1.obj = obj_2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
GDTEST_RUNTIME_ERROR
>> SCRIPT ERROR
>> on function: test()
>> runtime/errors/invalid_property_assignment.gd
>> 9
>> Invalid assignment of property or key 'obj' with value of type 'RefCounted (MyObj)' on a base object of type 'RefCounted (MyObj)'.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# https://github.com/godotengine/godot/issues/90086

class MyObj:
var obj : WeakRef

func test():
var obj_1 = MyObj.new()
var obj_2 = MyObj.new()
assert(obj_2.get_reference_count() == 1)
obj_1.set(&"obj", obj_2)
assert(obj_2.get_reference_count() == 1)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GDTEST_OK
Loading