From dbcb854cd2ce9c3069a70841a534fea3125eec88 Mon Sep 17 00:00:00 2001 From: Sahra Zhou <63219465+Sahra-Zhou@users.noreply.github.com> Date: Sun, 26 Mar 2023 15:20:00 -0700 Subject: [PATCH] Fix crash when scaling something with 0 width or height (#1078) * resolve NaN value when trying to change scale value from zero to other numbers * resolve NaN value when trying to change scale value from zero to other numbers --------- Co-authored-by: Keavon Chambers --- document-legacy/src/layers/shape_layer.rs | 2 +- .../portfolio/document/properties_panel/utility_functions.rs | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/document-legacy/src/layers/shape_layer.rs b/document-legacy/src/layers/shape_layer.rs index 48873ba3..43236f7c 100644 --- a/document-legacy/src/layers/shape_layer.rs +++ b/document-legacy/src/layers/shape_layer.rs @@ -59,7 +59,7 @@ impl LayerData for ShapeLayer { fn bounding_box(&self, transform: glam::DAffine2, _render_data: &RenderData) -> Option<[DVec2; 2]> { let mut subpath = self.shape.clone(); - if transform.matrix2 == DMat2::ZERO { + if transform.matrix2 == DMat2::ZERO || !transform.is_finite() { return None; } subpath.apply_affine(transform); diff --git a/editor/src/messages/portfolio/document/properties_panel/utility_functions.rs b/editor/src/messages/portfolio/document/properties_panel/utility_functions.rs index c7804447..60ed8b06 100644 --- a/editor/src/messages/portfolio/document/properties_panel/utility_functions.rs +++ b/editor/src/messages/portfolio/document/properties_panel/utility_functions.rs @@ -48,6 +48,9 @@ pub fn apply_transform_operation(layer: &Layer, transform_op: TransformOp, value // Find the delta transform let mut delta = layer.transform.inverse() * transform; + if !delta.is_finite() { + return layer.transform.to_cols_array(); + } // Preserve aspect ratio if matches!(transform_op, TransformOp::ScaleX | TransformOp::Width) && layer.preserve_aspect {