From fc0b6590664d56c4ace4a6c9cd8f7e83d474fc1b Mon Sep 17 00:00:00 2001 From: Rob Blair Date: Fri, 13 Jun 2025 10:47:56 -0400 Subject: [PATCH] Fix divide by zero in Bevel. The [Fix #125024: Bevel offset - eliminate divide by 0] (#126309) in response to [Bevel Modifier creates unwanted geometries] (#125024) created "divide by 0" situations when checking for clamp overlap geometry in the bevel modifier. This PR eliminates this undefined behavior. Original PR by Rob Blair. Modified by make format and added a needed include. --- source/blender/bmesh/tools/bmesh_bevel.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/blender/bmesh/tools/bmesh_bevel.cc b/source/blender/bmesh/tools/bmesh_bevel.cc index 695f24eb7c7..8645b3a29b9 100644 --- a/source/blender/bmesh/tools/bmesh_bevel.cc +++ b/source/blender/bmesh/tools/bmesh_bevel.cc @@ -18,6 +18,7 @@ #include "BLI_alloca.h" #include "BLI_math_base.h" +#include "BLI_math_base_safe.h" #include "BLI_math_geom.h" #include "BLI_math_matrix.h" #include "BLI_math_rotation.h" @@ -7551,7 +7552,8 @@ static float geometry_collide_offset(BevelParams *bp, EdgeHalf *eb) * The intersection of these two corner vectors is the collapse point. * The length of edge B divided by the projection of these vectors onto edge B * is the number of 'offsets' that can be accommodated. */ - float offsets_projected_on_B = (ka + cos1 * kb) / sin1 + (kc + cos2 * kb) / sin2; + float offsets_projected_on_B = safe_divide(ka + cos1 * kb, sin1) + + safe_divide(kc + cos2 * kb, sin2); if (offsets_projected_on_B > BEVEL_EPSILON) { offsets_projected_on_B = bp->offset * (len_v3v3(vb->co, vc->co) / offsets_projected_on_B); if (offsets_projected_on_B > BEVEL_EPSILON) {