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:
parent
a08a08cb4c
commit
c3c3807b05
Notes:
blender-bot
2023-02-14 06:49:57 +01:00
Referenced by issue #82988, Crash when using curve deform Referenced by issue #77348, Blender LTS: Maintenance Task 2.83
|
@ -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)) {
|
||||
|
|
Loading…
Reference in New Issue