[Bf-blender-cvs] [436fd5663e6] master: Fix T82988: Div by zero with curve deform modifier
Robert Guetzkow
noreply at git.blender.org
Wed Nov 25 15:22:50 CET 2020
Commit: 436fd5663e64979d59cacc12323053f860ce39b0
Author: Robert Guetzkow
Date: Wed Nov 25 14:26:53 2020 +0100
Branches: master
https://developer.blender.org/rB436fd5663e64979d59cacc12323053f860ce39b0
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/curve_deform.c
===================================================================
diff --git a/source/blender/blenkernel/intern/curve_deform.c b/source/blender/blenkernel/intern/curve_deform.c
index 049bd46c434..4725be6d302 100644
--- a/source/blender/blenkernel/intern/curve_deform.c
+++ b/source/blender/blenkernel/intern/curve_deform.c
@@ -163,16 +163,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]) / (ob_curve->runtime.curve_cache->path->totdist);
+ if (LIKELY(ob_curve->runtime.curve_cache->path->totdist > FLT_EPSILON)) {
+ fac = -(co[index] - cd->dmax[index]) / (ob_curve->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(ob_curve->runtime.curve_cache->path->totdist > FLT_EPSILON)) {
More information about the Bf-blender-cvs
mailing list