From fa1fde7083554ac6e5f33de9ae57714d83b77014 Mon Sep 17 00:00:00 2001 From: desuwa Date: Tue, 6 Apr 2021 23:58:13 +0200 Subject: [PATCH] core: Ensure the new scale is finite when setting the width / height of display objects. --- core/src/display_object.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/core/src/display_object.rs b/core/src/display_object.rs index 5369f26c5..fd31614d8 100644 --- a/core/src/display_object.rs +++ b/core/src/display_object.rs @@ -605,10 +605,19 @@ pub trait TDisplayObject<'gc>: let rotation = self.rotation(gc_context); let cos = f64::abs(f64::cos(rotation.into_radians())); let sin = f64::abs(f64::sin(rotation.into_radians())); - let new_scale_x = aspect_ratio * (cos * target_scale_x + sin * target_scale_y) + let mut new_scale_x = aspect_ratio * (cos * target_scale_x + sin * target_scale_y) / ((cos + aspect_ratio * sin) * (aspect_ratio * cos + sin)); - let new_scale_y = + let mut new_scale_y = (sin * prev_scale_x + aspect_ratio * cos * prev_scale_y) / (aspect_ratio * cos + sin); + + if !new_scale_x.is_finite() { + new_scale_x = 0.0; + } + + if !new_scale_y.is_finite() { + new_scale_y = 0.0; + } + self.set_scale_x(gc_context, Percent::from_unit(new_scale_x)); self.set_scale_y(gc_context, Percent::from_unit(new_scale_y)); } @@ -644,10 +653,19 @@ pub trait TDisplayObject<'gc>: let rotation = self.rotation(gc_context); let cos = f64::abs(f64::cos(rotation.into_radians())); let sin = f64::abs(f64::sin(rotation.into_radians())); - let new_scale_x = + let mut new_scale_x = (aspect_ratio * cos * prev_scale_x + sin * prev_scale_y) / (aspect_ratio * cos + sin); - let new_scale_y = aspect_ratio * (sin * target_scale_x + cos * target_scale_y) + let mut new_scale_y = aspect_ratio * (sin * target_scale_x + cos * target_scale_y) / ((cos + aspect_ratio * sin) * (aspect_ratio * cos + sin)); + + if !new_scale_x.is_finite() { + new_scale_x = 0.0; + } + + if !new_scale_y.is_finite() { + new_scale_y = 0.0; + } + self.set_scale_x(gc_context, Percent::from_unit(new_scale_x)); self.set_scale_y(gc_context, Percent::from_unit(new_scale_y)); }