From 3b8c63c4a6a3325707ef624942ea50834634e45c Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Sat, 16 Mar 2024 19:03:41 +0200 Subject: [PATCH] Fix crash due to division by zero when locking two or three ValueSliders and one of them has the value of 0 and the user attempts to change it --- CHANGELOG.md | 1 + project.godot | 2 +- src/UI/Nodes/ValueSliderV2.gd | 6 ++++-- src/UI/Nodes/ValueSliderV3.gd | 15 +++++++++------ 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5183e62959d..79071cfc27ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ Built using Godot 3.5.2 - Optimize canvas drawing by only updating it when the image(s) have changed. [ac6a4db43d9296ebc03e639d8199dd3878a25d86](https://github.com/Orama-Interactive/Pixelorama/commit/ac6a4db43d9296ebc03e639d8199dd3878a25d86) - Fix bug where using shortcuts to switch between frames also moved the selection, causing deletions. - Pxo files can now be loaded from the Open menu option in the Web version. [3dcc51705a999145e53a8e6d4de217dc03b0f147](https://github.com/Orama-Interactive/Pixelorama/commit/3dcc51705a999145e53a8e6d4de217dc03b0f147) +- Fixed crash due to division by zero when locking two or three ValueSliders, and one of them has the value of 0 and the user attempts to change it. - Fixed exporting selected layers not including the non-selected frames. - The ellipse tool no longer produces gaps with large sizes. [4f3a7a305a264e0d2fe86c201af76eca4b2fea0a](https://github.com/Orama-Interactive/Pixelorama/commit/4f3a7a305a264e0d2fe86c201af76eca4b2fea0a) - Fix "visible layers" option on the export dialog producing wrong results. [346d1f071a8c6b1defb1072d39aea9c642f1ef59](https://github.com/Orama-Interactive/Pixelorama/commit/346d1f071a8c6b1defb1072d39aea9c642f1ef59) diff --git a/project.godot b/project.godot index d0172fb7bd2a..38b74c312b3b 100644 --- a/project.godot +++ b/project.godot @@ -343,7 +343,7 @@ config/icon="res://assets/graphics/icons/icon.png" config/macos_native_icon="res://assets/graphics/icons/icon.icns" config/windows_native_icon="res://assets/graphics/icons/icon.ico" config/custom_user_dir_name.X11="pixelorama" -config/Version="v0.11.4-rc3" +config/Version="v0.11.4-rc2" config/ExtensionsAPI_Version=3 config/Pxo_Version=2 diff --git a/src/UI/Nodes/ValueSliderV2.gd b/src/UI/Nodes/ValueSliderV2.gd index da483296ed17..9a83bf7b4194 100644 --- a/src/UI/Nodes/ValueSliderV2.gd +++ b/src/UI/Nodes/ValueSliderV2.gd @@ -48,7 +48,8 @@ func _gcd(a: int, b: int) -> int: func _on_X_value_changed(val: float) -> void: value.x = val if _locked_ratio: - self.value.y = max(min_value.y, (value.x / ratio.x) * ratio.y) + if not is_zero_approx(ratio.x): + self.value.y = max(min_value.y, (value.x / ratio.x) * ratio.y) if _can_emit_signal: emit_signal("value_changed", value) @@ -56,7 +57,8 @@ func _on_X_value_changed(val: float) -> void: func _on_Y_value_changed(val: float) -> void: value.y = val if _locked_ratio: - self.value.x = max(min_value.x, (value.y / ratio.y) * ratio.x) + if not is_zero_approx(ratio.y): + self.value.x = max(min_value.x, (value.y / ratio.y) * ratio.x) if _can_emit_signal: emit_signal("value_changed", value) diff --git a/src/UI/Nodes/ValueSliderV3.gd b/src/UI/Nodes/ValueSliderV3.gd index 4e23b03fd73d..f06780c27be6 100644 --- a/src/UI/Nodes/ValueSliderV3.gd +++ b/src/UI/Nodes/ValueSliderV3.gd @@ -50,8 +50,9 @@ func _gcd(a: int, b: int) -> int: func _on_X_value_changed(val: float) -> void: value.x = val if _locked_ratio: - self.value.y = max(min_value.y, (value.x / ratio.x) * ratio.y) - self.value.z = max(min_value.z, (value.x / ratio.x) * ratio.z) + if not is_zero_approx(ratio.x): + self.value.y = max(min_value.y, (value.x / ratio.x) * ratio.y) + self.value.z = max(min_value.z, (value.x / ratio.x) * ratio.z) if _can_emit_signal: emit_signal("value_changed", value) @@ -59,8 +60,9 @@ func _on_X_value_changed(val: float) -> void: func _on_Y_value_changed(val: float) -> void: value.y = val if _locked_ratio: - self.value.x = max(min_value.x, (value.y / ratio.y) * ratio.x) - self.value.z = max(min_value.z, (value.y / ratio.y) * ratio.z) + if not is_zero_approx(ratio.y): + self.value.x = max(min_value.x, (value.y / ratio.y) * ratio.x) + self.value.z = max(min_value.z, (value.y / ratio.y) * ratio.z) if _can_emit_signal: emit_signal("value_changed", value) @@ -68,8 +70,9 @@ func _on_Y_value_changed(val: float) -> void: func _on_Z_value_changed(val: float) -> void: value.z = val if _locked_ratio: - self.value.x = max(min_value.x, (value.z / ratio.z) * ratio.x) - self.value.y = max(min_value.y, (value.z / ratio.z) * ratio.y) + if not is_zero_approx(ratio.z): + self.value.x = max(min_value.x, (value.z / ratio.z) * ratio.x) + self.value.y = max(min_value.y, (value.z / ratio.z) * ratio.y) if _can_emit_signal: emit_signal("value_changed", value)