From 484c899c942678dfb02c5f4907756b0ec0e59e50 Mon Sep 17 00:00:00 2001 From: Raul Fernandez Date: Wed, 24 Apr 2024 12:07:36 -0400 Subject: [PATCH 1/4] fix --- .../blenkernel/intern/multires_unsubdivide.cc | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/source/blender/blenkernel/intern/multires_unsubdivide.cc b/source/blender/blenkernel/intern/multires_unsubdivide.cc index fd27c74a85e..955b18a7804 100644 --- a/source/blender/blenkernel/intern/multires_unsubdivide.cc +++ b/source/blender/blenkernel/intern/multires_unsubdivide.cc @@ -839,19 +839,29 @@ static void multires_unsubdivide_get_grid_corners_on_base_mesh(BMFace *f1, BMEdge *edge_y = initial_edge_y; /* Do an edge step until it finds a tagged vertex, which is part of the base mesh. */ + /* edge_y = edge_step(current_vertex_y, edge_y, ¤t_vertex_y); + while (edge_y && !BM_elem_flag_test(current_vertex_y, BM_ELEM_TAG)) + this test with hidden faces enter in an infinite loop by returning the same null + edge in edge_step() and the same current_vertex_y + + */ /* x axis */ edge_x = edge_step(current_vertex_x, edge_x, ¤t_vertex_x); - while (!BM_elem_flag_test(current_vertex_x, BM_ELEM_TAG)) { + while (edge_x && !BM_elem_flag_test(current_vertex_x, BM_ELEM_TAG)) { edge_x = edge_step(current_vertex_x, edge_x, ¤t_vertex_x); } - (*r_corner_x) = current_vertex_x; + if (edge_x) { + (*r_corner_x) = current_vertex_x; + } /* Same for y axis */ edge_y = edge_step(current_vertex_y, edge_y, ¤t_vertex_y); - while (!BM_elem_flag_test(current_vertex_y, BM_ELEM_TAG)) { + while (edge_y && !BM_elem_flag_test(current_vertex_y, BM_ELEM_TAG)) { edge_y = edge_step(current_vertex_y, edge_y, ¤t_vertex_y); } - (*r_corner_y) = current_vertex_y; + if (edge_y) { + (*r_corner_y) = current_vertex_y; + } } static BMesh *get_bmesh_from_mesh(Mesh *mesh) -- 2.30.2 From 20952d3ebec8873d7b3c715bfdaf8c0be9caac79 Mon Sep 17 00:00:00 2001 From: Raul Fernandez Date: Thu, 25 Apr 2024 12:29:00 -0400 Subject: [PATCH 2/4] nit --- source/blender/blenkernel/intern/multires_unsubdivide.cc | 6 ------ 1 file changed, 6 deletions(-) diff --git a/source/blender/blenkernel/intern/multires_unsubdivide.cc b/source/blender/blenkernel/intern/multires_unsubdivide.cc index 955b18a7804..42257212f1b 100644 --- a/source/blender/blenkernel/intern/multires_unsubdivide.cc +++ b/source/blender/blenkernel/intern/multires_unsubdivide.cc @@ -839,12 +839,6 @@ static void multires_unsubdivide_get_grid_corners_on_base_mesh(BMFace *f1, BMEdge *edge_y = initial_edge_y; /* Do an edge step until it finds a tagged vertex, which is part of the base mesh. */ - /* edge_y = edge_step(current_vertex_y, edge_y, ¤t_vertex_y); - while (edge_y && !BM_elem_flag_test(current_vertex_y, BM_ELEM_TAG)) - this test with hidden faces enter in an infinite loop by returning the same null - edge in edge_step() and the same current_vertex_y - - */ /* x axis */ edge_x = edge_step(current_vertex_x, edge_x, ¤t_vertex_x); while (edge_x && !BM_elem_flag_test(current_vertex_x, BM_ELEM_TAG)) { -- 2.30.2 From 8a7882250b981e19dddef3db3fcf79bd4922801a Mon Sep 17 00:00:00 2001 From: Raul Fernandez Date: Tue, 30 Apr 2024 16:07:33 -0400 Subject: [PATCH 3/4] handled uninitialized edges --- .../blenkernel/intern/multires_unsubdivide.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/source/blender/blenkernel/intern/multires_unsubdivide.cc b/source/blender/blenkernel/intern/multires_unsubdivide.cc index 42257212f1b..fe4bad941e9 100644 --- a/source/blender/blenkernel/intern/multires_unsubdivide.cc +++ b/source/blender/blenkernel/intern/multires_unsubdivide.cc @@ -845,7 +845,10 @@ static void multires_unsubdivide_get_grid_corners_on_base_mesh(BMFace *f1, edge_x = edge_step(current_vertex_x, edge_x, ¤t_vertex_x); } if (edge_x) { - (*r_corner_x) = current_vertex_x; + *r_corner_x = current_vertex_x; + } + else { + *r_corner_x = nullptr; } /* Same for y axis */ @@ -854,7 +857,10 @@ static void multires_unsubdivide_get_grid_corners_on_base_mesh(BMFace *f1, edge_y = edge_step(current_vertex_y, edge_y, ¤t_vertex_y); } if (edge_y) { - (*r_corner_y) = current_vertex_y; + *r_corner_y = current_vertex_y; + } + else { + *r_corner_y = nullptr; } } @@ -1047,6 +1053,8 @@ static void multires_unsubdivide_extract_grids(MultiresUnsubdivideContext *conte * base mesh of the face of grid that is going to be extracted. */ BMVert *corner_x, *corner_y; multires_unsubdivide_get_grid_corners_on_base_mesh(l->f, l->e, &corner_x, &corner_y); + if (!corner_x || !corner_y) + continue; /* Map the two obtained vertices to the base mesh. */ const int corner_x_index = orig_to_base_vmap[BM_elem_index_get(corner_x)]; -- 2.30.2 From 7e66df5575658916603cc0d7c41391c4aac7518f Mon Sep 17 00:00:00 2001 From: Raul Fernandez Date: Tue, 30 Apr 2024 16:14:13 -0400 Subject: [PATCH 4/4] nit --- source/blender/blenkernel/intern/multires_unsubdivide.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/blender/blenkernel/intern/multires_unsubdivide.cc b/source/blender/blenkernel/intern/multires_unsubdivide.cc index fe4bad941e9..aec366fbde2 100644 --- a/source/blender/blenkernel/intern/multires_unsubdivide.cc +++ b/source/blender/blenkernel/intern/multires_unsubdivide.cc @@ -1053,8 +1053,9 @@ static void multires_unsubdivide_extract_grids(MultiresUnsubdivideContext *conte * base mesh of the face of grid that is going to be extracted. */ BMVert *corner_x, *corner_y; multires_unsubdivide_get_grid_corners_on_base_mesh(l->f, l->e, &corner_x, &corner_y); - if (!corner_x || !corner_y) + if (!corner_x || !corner_y) { continue; + } /* Map the two obtained vertices to the base mesh. */ const int corner_x_index = orig_to_base_vmap[BM_elem_index_get(corner_x)]; -- 2.30.2