[Bf-blender-cvs] [944ab366578] blender-v2.82-release: BLI_kdopbvh: Prevent division by zero in raycast

mano-wii noreply at git.blender.org
Thu Jan 30 12:36:44 CET 2020


Commit: 944ab366578f2447c6c31370867e689fc661a972
Author: mano-wii
Date:   Thu Jan 30 08:36:35 2020 -0300
Branches: blender-v2.82-release
https://developer.blender.org/rB944ab366578f2447c6c31370867e689fc661a972

BLI_kdopbvh: Prevent division by zero in raycast

===================================================================

M	source/blender/blenlib/intern/BLI_kdopbvh.c

===================================================================

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;



More information about the Bf-blender-cvs mailing list