[Bf-blender-cvs] [c3c3807b059] blender-v2.83-release: Fix T82988: Div by zero with curve deform modifier

Robert Guetzkow noreply at git.blender.org
Wed Dec 2 08:50:18 CET 2020


Commit: c3c3807b059ddfc87a9fbc2575f4d821ddc0a248
Author: Robert Guetzkow
Date:   Wed Nov 25 14:26:53 2020 +0100
Branches: blender-v2.83-release
https://developer.blender.org/rBc3c3807b059ddfc87a9fbc2575f4d821ddc0a248

Fix T82988: Div by zero with curve deform modifier

In `calc_curve_deform` a factor is calculated without checking if
the divisior is zero or close to zero. This patch adds the missing
checks and sets the factor to zero if the division shouldn't be
computed.

Reviewed By: mont29

Differential Revision: https://developer.blender.org/D9645

===================================================================

M	source/blender/blenkernel/intern/lattice.c

===================================================================

diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c
index d371af93bb7..34216e08650 100644
--- a/source/blender/blenkernel/intern/lattice.c
+++ b/source/blender/blenkernel/intern/lattice.c
@@ -664,16 +664,33 @@ static bool calc_curve_deform(
   if (is_neg_axis) {
     index = axis - 3;
     if (cu->flag & CU_STRETCH) {
-      fac = -(co[index] - cd->dmax[index]) / (cd->dmax[index] - cd->dmin[index]);
+      const float divisor = cd->dmax[index] - cd->dmin[index];
+      if (LIKELY(divisor > FLT_EPSILON)) {
+        fac = -(co[index] - cd->dmax[index]) / divisor;
+      }
+      else {
+        fac = 0.0f;
+      }
     }
     else {
-      fac = -(co[index] - cd->dmax[index]) / (par->runtime.curve_cache->path->totdist);
+      if (LIKELY(par->runtime.curve_cache->path->totdist > FLT_EPSILON)) {
+        fac = -(co[index] - cd->dmax[index]) / (par->runtime.curve_cache->path->totdist);
+      }
+      else {
+        fac = 0.0f;
+      }
     }
   }
   else {
     index = axis;
     if (cu->flag & CU_STRETCH) {
-      fac = (co[index] - cd->dmin[index]) / (cd->dmax[index] - cd->dmin[index]);
+      const float divisor = cd->dmax[index] - cd->dmin[index];
+      if (LIKELY(divisor > FLT_EPSILON)) {
+        fac = (co[index] - cd->dmin[index]) / divisor;
+      }
+      else {
+        fac = 0.0f;
+      }
     }
     else {
       if (LIKELY(par->runtime.curve_cache->path->totdist > FLT_EPSILON)) {



More information about the Bf-blender-cvs mailing list