From 8f3e2c96eb91027ea050c1e2aacf2cd0e1bf35d9 Mon Sep 17 00:00:00 2001 From: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> Date: Tue, 2 Apr 2024 15:49:56 +0200 Subject: [Core] Fix `Variant::construct` of `Object` Variant type was not updated correctly causing leaks in ref-counted --- .../scripts/runtime/errors/invalid_property_assignment.gd | 9 +++++++++ .../scripts/runtime/errors/invalid_property_assignment.out | 6 ++++++ .../tests/scripts/runtime/features/set_does_not_leak.gd | 11 +++++++++++ .../tests/scripts/runtime/features/set_does_not_leak.out | 1 + 4 files changed, 27 insertions(+) create mode 100644 modules/gdscript/tests/scripts/runtime/errors/invalid_property_assignment.gd create mode 100644 modules/gdscript/tests/scripts/runtime/errors/invalid_property_assignment.out create mode 100644 modules/gdscript/tests/scripts/runtime/features/set_does_not_leak.gd create mode 100644 modules/gdscript/tests/scripts/runtime/features/set_does_not_leak.out (limited to 'modules/gdscript/tests/scripts') diff --git a/modules/gdscript/tests/scripts/runtime/errors/invalid_property_assignment.gd b/modules/gdscript/tests/scripts/runtime/errors/invalid_property_assignment.gd new file mode 100644 index 0000000000..3724c8c713 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/invalid_property_assignment.gd @@ -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 diff --git a/modules/gdscript/tests/scripts/runtime/errors/invalid_property_assignment.out b/modules/gdscript/tests/scripts/runtime/errors/invalid_property_assignment.out new file mode 100644 index 0000000000..dfca5b1eca --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/invalid_property_assignment.out @@ -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)'. diff --git a/modules/gdscript/tests/scripts/runtime/features/set_does_not_leak.gd b/modules/gdscript/tests/scripts/runtime/features/set_does_not_leak.gd new file mode 100644 index 0000000000..e1aba83507 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/set_does_not_leak.gd @@ -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) diff --git a/modules/gdscript/tests/scripts/runtime/features/set_does_not_leak.out b/modules/gdscript/tests/scripts/runtime/features/set_does_not_leak.out new file mode 100644 index 0000000000..d73c5eb7cd --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/set_does_not_leak.out @@ -0,0 +1 @@ +GDTEST_OK -- cgit v1.2.3