Masking: prevent crashes in cases when mask spline is axis aligned
authorLukas Toenne <lukas.toenne@googlemail.com>
Fri, 20 Jul 2012 17:28:42 +0000 (17:28 +0000)
committerLukas Toenne <lukas.toenne@googlemail.com>
Fri, 20 Jul 2012 17:28:42 +0000 (17:28 +0000)
source/blender/blenkernel/intern/mask.c

index a8c95a4fc713b19b25319d3516d69ce9a873ec7c..e63dfdf4445372f244a114902e6c4ff53a7a2999 100644 (file)
@@ -574,12 +574,25 @@ static void spline_feather_collapse_inner_loops(MaskSpline *spline, float (*feat
                        max_delta_y = delta;
        }
 
+       /* prevent divisionsby zero by ensuring bounding box is not collapsed */
+       if (max[0] - min[0] < FLT_EPSILON) {
+               max[0] += 0.01f;
+               min[0] -= 0.01f;
+       }
+
+       if (max[1] - min[1] < FLT_EPSILON) {
+               max[1] += 0.01f;
+               min[1] -= 0.01f;
+       }
+
        /* use dynamically calculated buckets per side, so we likely wouldn't
         * run into a situation when segment doesn't fit two buckets which is
         * pain collecting candidates for intersection
         */
+
        max_delta_x /= max[0] - min[0];
        max_delta_y /= max[1] - min[1];
+
        max_delta = MAX2(max_delta_x, max_delta_y);
 
        buckets_per_side = MIN2(512, 0.9f / max_delta);