Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Guetzkow <gitcommit@outlook.de>2020-11-25 16:26:53 +0300
committerRobert Guetzkow <gitcommit@outlook.de>2020-11-25 17:18:18 +0300
commit436fd5663e64979d59cacc12323053f860ce39b0 (patch)
treef253956d8194507f5c05c9ad48f60e073a5aaefc /source/blender/blenkernel/intern/curve_deform.c
parent4a179e8e3e0fe39b76baa3cba753491a8083de51 (diff)
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
Diffstat (limited to 'source/blender/blenkernel/intern/curve_deform.c')
-rw-r--r--source/blender/blenkernel/intern/curve_deform.c23
1 files changed, 20 insertions, 3 deletions
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)) {