From bbc6bb34689cd8654fd46e9a00a5835794501e56 Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Wed, 8 Mar 2023 11:16:06 -0300 Subject: [PATCH] Fix #105556: weld modifier crashes when merging N-gons The logic for counting possible new polygons was incorrect. --- source/blender/geometry/intern/mesh_merge_by_distance.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/blender/geometry/intern/mesh_merge_by_distance.cc b/source/blender/geometry/intern/mesh_merge_by_distance.cc index fbd06791bd8..f0f1e02ae1d 100644 --- a/source/blender/geometry/intern/mesh_merge_by_distance.cc +++ b/source/blender/geometry/intern/mesh_merge_by_distance.cc @@ -836,9 +836,9 @@ static void weld_poly_loop_ctx_alloc(Span mpoly, poly_map[i] = wpoly_len++; if (totloop > 5 && vert_ctx_len > 1) { - int max_new = (totloop / 3) - 1; - vert_ctx_len /= 2; - maybe_new_poly += MIN2(max_new, vert_ctx_len); + /* Each untouched vertex pair is a candidate for a new polygon. */ + int max_new = std::min(vert_ctx_len, (totloop - vert_ctx_len) / 2); + maybe_new_poly += max_new; CLAMP_MIN(max_ctx_poly_len, totloop); } }