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
committerJeroen Bakker <jeroen@blender.org>2020-12-02 10:40:49 +0300
commitc3c3807b059ddfc87a9fbc2575f4d821ddc0a248 (patch)
tree5acddbe55aaf3388a3ad1529b863bbf622a8b375
parenta08a08cb4c26627c05ad6089030223e8313a0073 (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
-rw-r--r--source/blender/blenkernel/intern/lattice.c23
1 files changed, 20 insertions, 3 deletions
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)) {