Bug 1393605 - Return Err(()) if determinant is not 1 or -1 while decomposing the 2d matrix. draft
authorBoris Chiou <boris.chiou@gmail.com>
Wed, 30 Aug 2017 12:03:25 +0800
changeset 656350 ee18275fa279cfca9830d5aaa753f8be878559ff
parent 655385 db7f19e26e571ae1dd309f5d2f387b06ba670c30
child 656351 1bd6180f9e39daa12b578eb84b33f658919a4872
push id77180
push userbmo:boris.chiou@gmail.com
push dateThu, 31 Aug 2017 03:19:24 +0000
bugs1393605
milestone57.0a1
Bug 1393605 - Return Err(()) if determinant is not 1 or -1 while decomposing the 2d matrix. This may happen in some cases, and we shouldn't panic in debug mode, so let's return Err(()) for it to fall back to discrete animation. MozReview-Commit-ID: 7L6hhBAt86n
servo/components/style/properties/helpers/animated_properties.mako.rs
--- a/servo/components/style/properties/helpers/animated_properties.mako.rs
+++ b/servo/components/style/properties/helpers/animated_properties.mako.rs
@@ -1687,18 +1687,18 @@ fn decompose_3d_matrix(mut matrix: Compu
 fn decompose_2d_matrix(matrix: &ComputedMatrix) -> Result<MatrixDecomposed3D, ()> {
     // The index is column-major, so the equivalent transform matrix is:
     // | m11 m21  0 m41 |  =>  | m11 m21 | and translate(m41, m42)
     // | m12 m22  0 m42 |      | m12 m22 |
     // |   0   0  1   0 |
     // |   0   0  0   1 |
     let (mut m11, mut m12) = (matrix.m11, matrix.m12);
     let (mut m21, mut m22) = (matrix.m21, matrix.m22);
+    // Check if this is a singular matrix.
     if m11 * m22 == m12 * m21 {
-        // singular matrix
         return Err(());
     }
 
     let mut scale_x = (m11 * m11 + m12 * m12).sqrt();
     m11 /= scale_x;
     m12 /= scale_x;
 
     let mut shear_xy = m11 * m21 + m12 * m22;
@@ -1706,18 +1706,20 @@ fn decompose_2d_matrix(matrix: &Computed
     m22 -= m12 * shear_xy;
 
     let scale_y = (m21 * m21 + m22 * m22).sqrt();
     m21 /= scale_y;
     m22 /= scale_y;
     shear_xy /= scale_y;
 
     let determinant = m11 * m22 - m12 * m21;
-    debug_assert!(0.99 < determinant.abs() && determinant.abs() < 1.01,
-                  "determinant should now be 1 or -1");
+    // Determinant should now be 1 or -1.
+    if 0.99 > determinant.abs() || determinant.abs() > 1.01 {
+        return Err(());
+    }
 
     if determinant < 0. {
         m11 = -m11;
         m12 = -m12;
         shear_xy = -shear_xy;
         scale_x = -scale_x;
     }