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:
authorBastien Montagne <bastien@blender.org>2021-06-14 12:06:35 +0300
committerBastien Montagne <bastien@blender.org>2021-06-14 13:32:38 +0300
commitb21db5e6988566dc3344b3293eb7e33234ec2597 (patch)
tree0bc664e2dfb2dce5b94062367ba54bc14eacb9bf /source/blender/blenlib/intern/math_geom.c
parent5add6f2ed93773e1231e3d52dc9fd963b3bfb9e7 (diff)
BLI_math: Fix several division-by-zero cases.
Those were caused by various tools used on degenerate geometry, see T79775. Note that fixes are as low-level as possible, to ensure they cover as much as possible of unreported issues too. We still probably have many more of those hidden in BLI_math though.
Diffstat (limited to 'source/blender/blenlib/intern/math_geom.c')
-rw-r--r--source/blender/blenlib/intern/math_geom.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index 508de506ae8..6b1730f8ee8 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -3344,6 +3344,13 @@ float closest_to_ray_v3(float r_close[3],
const float ray_dir[3])
{
float h[3], lambda;
+
+ if (UNLIKELY(is_zero_v3(ray_dir))) {
+ lambda = 0.0f;
+ copy_v3_v3(r_close, ray_orig);
+ return lambda;
+ }
+
sub_v3_v3v3(h, p, ray_orig);
lambda = dot_v3v3(ray_dir, h) / dot_v3v3(ray_dir, ray_dir);
madd_v3_v3v3fl(r_close, ray_orig, ray_dir, lambda);
@@ -4467,7 +4474,7 @@ void interp_weights_poly_v2(float *w, float v[][2], const int n, const float co[
d_curr = d_next;
DIR_V2_SET(&d_next, v_next, co);
ht = mean_value_half_tan_v2_db(&d_curr, &d_next);
- w[i_curr] = (float)((ht_prev + ht) / d_curr.len);
+ w[i_curr] = (d_curr.len == 0.0) ? 0.0f : (float)((ht_prev + ht) / d_curr.len);
totweight += w[i_curr];
/* step */