Repository: godotengine/godot (language: cpp)

Issue:
Editor NaN when scaling CanvasItem on a negative axis
### Tested versions

Reproducible in: 4.4.dev5 [9e6098432], 4.4.beta1, 4.4.stable, 4.4.1.stable, 4.5.dev2
Not reproducible in: 4.4.dev4, 4.4.dev3, 4.3.stable

### System information

Godot v4.4.1.stable - Debian GNU/Linux 12 (bookworm) 12 on X11 - X11 display driver, Multi-window, 1 monitor - Vulkan (Forward+) - integrated AMD Radeon Graphics (RADV RENOIR) - AMD Ryzen 5 PRO 4650U with Radeon Graphics (12 threads)

### Issue description

In the editor, resizing a Node2D along an axis that already has a negative scale value results in the scale becoming NaN.


### Steps to reproduce

https://github.com/user-attachments/assets/5bc51c8e-95a6-4900-869a-e15d79e32b59

### Minimal reproduction project (MRP)

N/A


Discussion / hints:

Fix patch:
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp
index f4685cb4e8ce..28749170e241 100644
--- a/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/editor/plugins/canvas_item_editor_plugin.cpp
@@ -2035,7 +2035,14 @@ bool CanvasItemEditor::_gui_input_scale(const Ref<InputEvent> &p_event) {
 			Size2 scale_max;
 			if (drag_type != DRAG_SCALE_BOTH) {
 				for (CanvasItem *ci : drag_selection) {
-					scale_max = scale_max.max(ci->_edit_get_scale());
+					Size2 scale = ci->_edit_get_scale();
+
+					if (Math::abs(scale.x) > Math::abs(scale_max.x)) {
+						scale_max.x = scale.x;
+					}
+					if (Math::abs(scale.y) > Math::abs(scale_max.y)) {
+						scale_max.y = scale.y;
+					}
 				}
 			}
 


Test patch: