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
This commit is contained in:
Robert Guetzkow 2020-11-25 14:26:53 +01:00
parent 4a179e8e3e
commit 436fd5663e
Notes: blender-bot 2023-02-14 09:44:56 +01:00
Referenced by issue #82988, Crash when using curve deform
Referenced by issue #77348, Blender LTS: Maintenance Task 2.83
1 changed files with 20 additions and 3 deletions

View File

@ -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)) {