From 66fda2aeea84395b69c8d94d6957927699976e6c Mon Sep 17 00:00:00 2001 From: George Marques Date: Wed, 11 Jan 2023 14:24:23 -0300 Subject: GDScript: Fix temp values being written without proper clear Temporary values in the stack were not being properly cleared when the return value of calls were discarded, which can cause memory issues especially for reference types like PackedByteArray. --- .../runtime/features/does_not_override_temp_values.gd | 17 +++++++++++++++++ .../runtime/features/does_not_override_temp_values.out | 2 ++ 2 files changed, 19 insertions(+) create mode 100644 modules/gdscript/tests/scripts/runtime/features/does_not_override_temp_values.gd create mode 100644 modules/gdscript/tests/scripts/runtime/features/does_not_override_temp_values.out (limited to 'modules/gdscript/tests') diff --git a/modules/gdscript/tests/scripts/runtime/features/does_not_override_temp_values.gd b/modules/gdscript/tests/scripts/runtime/features/does_not_override_temp_values.gd new file mode 100644 index 0000000000..1d4b400d81 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/does_not_override_temp_values.gd @@ -0,0 +1,17 @@ +# https://github.com/godotengine/godot/issues/71177 + +func test(): + builtin_method() + builtin_method_static() + print("done") + +func builtin_method(): + var pba := PackedByteArray() + @warning_ignore(return_value_discarded) + pba.resize(1) # Built-in validated. + + +func builtin_method_static(): + var _pba := PackedByteArray() + @warning_ignore(return_value_discarded) + Vector2.from_angle(PI) # Static built-in validated. diff --git a/modules/gdscript/tests/scripts/runtime/features/does_not_override_temp_values.out b/modules/gdscript/tests/scripts/runtime/features/does_not_override_temp_values.out new file mode 100644 index 0000000000..8e68c97774 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/does_not_override_temp_values.out @@ -0,0 +1,2 @@ +GDTEST_OK +done -- cgit v1.2.3