diff options
author | mano-wii <germano.costa@ig.com.br> | 2020-01-30 14:36:35 +0300 |
---|---|---|
committer | mano-wii <germano.costa@ig.com.br> | 2020-01-30 14:36:35 +0300 |
commit | 944ab366578f2447c6c31370867e689fc661a972 (patch) | |
tree | c4a8ca389d6333f7046deac41ec633db3496ad87 /source/blender/blenlib/intern/BLI_kdopbvh.c | |
parent | 87b551e8365954d03d1c27303b9776deefd4e4d3 (diff) |
BLI_kdopbvh: Prevent division by zero in raycast
Diffstat (limited to 'source/blender/blenlib/intern/BLI_kdopbvh.c')
-rw-r--r-- | source/blender/blenlib/intern/BLI_kdopbvh.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c index 252e7caa149..50381f2fb18 100644 --- a/source/blender/blenlib/intern/BLI_kdopbvh.c +++ b/source/blender/blenlib/intern/BLI_kdopbvh.c @@ -1819,11 +1819,16 @@ static void bvhtree_ray_cast_data_precalc(BVHRayCastData *data, int flag) for (i = 0; i < 3; i++) { data->ray_dot_axis[i] = dot_v3v3(data->ray.direction, bvhtree_kdop_axes[i]); - data->idot_axis[i] = 1.0f / data->ray_dot_axis[i]; if (fabsf(data->ray_dot_axis[i]) < FLT_EPSILON) { - data->ray_dot_axis[i] = 0.0; + data->ray_dot_axis[i] = 0.0f; + /* Sign is not important in this case, `data->index` is adjusted anyway. */ + data->idot_axis[i] = FLT_MAX; } + else { + data->idot_axis[i] = 1.0f / data->ray_dot_axis[i]; + } + data->index[2 * i] = data->idot_axis[i] < 0.0f ? 1 : 0; data->index[2 * i + 1] = 1 - data->index[2 * i]; data->index[2 * i] += 2 * i; |