summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2020-01-13 12:13:45 +0100
committerRémi Verschelde <rverschelde@gmail.com>2020-01-13 12:20:15 +0100
commit100f50b7df7312f8fc56df7fd3e18427678bd957 (patch)
treeba91e4d979ef4bedb09191e9535b6586f32c15a9 /scene
parent52f44e72b61a8e9e923454bacdcf62de1b1c6309 (diff)
Control/Light2D: Preventing setting 0 as scale as for Node2D
Triggers errors in `Transform2D::affine_invert()`. Fixes #26510. Fixes https://github.com/godotengine/godot/issues/24997#issuecomment-457951639.
Diffstat (limited to 'scene')
-rw-r--r--scene/2d/light_2d.cpp4
-rw-r--r--scene/2d/node_2d.cpp1
-rw-r--r--scene/gui/control.cpp5
3 files changed, 10 insertions, 0 deletions
diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp
index eb66265010..1bffaf8084 100644
--- a/scene/2d/light_2d.cpp
+++ b/scene/2d/light_2d.cpp
@@ -189,6 +189,10 @@ float Light2D::get_energy() const {
void Light2D::set_texture_scale(float p_scale) {
_scale = p_scale;
+ // Avoid having 0 scale values, can lead to errors in physics and rendering.
+ if (_scale == 0) {
+ _scale = CMP_EPSILON;
+ }
VS::get_singleton()->canvas_light_set_scale(canvas_light, _scale);
item_rect_changed();
}
diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp
index 7bbc7577ed..7deebe9b27 100644
--- a/scene/2d/node_2d.cpp
+++ b/scene/2d/node_2d.cpp
@@ -173,6 +173,7 @@ void Node2D::set_scale(const Size2 &p_scale) {
if (_xform_dirty)
((Node2D *)this)->_update_xform_values();
_scale = p_scale;
+ // Avoid having 0 scale values, can lead to errors in physics and rendering.
if (_scale.x == 0)
_scale.x = CMP_EPSILON;
if (_scale.y == 0)
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index 9a67745e0d..4f499af186 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -2682,6 +2682,11 @@ Vector2 Control::get_pivot_offset() const {
void Control::set_scale(const Vector2 &p_scale) {
data.scale = p_scale;
+ // Avoid having 0 scale values, can lead to errors in physics and rendering.
+ if (data.scale.x == 0)
+ data.scale.x = CMP_EPSILON;
+ if (data.scale.y == 0)
+ data.scale.y = CMP_EPSILON;
update();
_notify_transform();
}