From 8602f893edc1da8802832c28be50a577ba3da89a Mon Sep 17 00:00:00 2001 From: Namit Bhutani Date: Wed, 16 Jul 2025 14:27:18 +0200 Subject: [PATCH] Fix #141811: Crash with remesh operator Fixes crash in the remesh operator by moving mesh spatial organization to appropriate execution contexts and using proper memory handling in spatial organization's face offset calculations. Pull Request: https://projects.blender.org/blender/blender/pulls/141842 --- source/blender/blenkernel/intern/mesh.cc | 5 +++-- source/blender/editors/object/object_remesh.cc | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/source/blender/blenkernel/intern/mesh.cc b/source/blender/blenkernel/intern/mesh.cc index 3fefb9d7ac9..65730547df2 100644 --- a/source/blender/blenkernel/intern/mesh.cc +++ b/source/blender/blenkernel/intern/mesh.cc @@ -886,8 +886,9 @@ void mesh_apply_spatial_organization(Mesh &mesh) corner_verts.copy_from(new_corner_verts); MutableSpan face_offsets = mesh.face_offsets_for_write(); - MutableSpan face_sizes_view = face_offsets.take_front(new_face_order.size()); - gather_group_sizes(old_faces, new_face_order, face_sizes_view); + Vector face_sizes(new_face_order.size()); + gather_group_sizes(old_faces, new_face_order, face_sizes); + face_offsets.take_front(face_sizes.size()).copy_from(face_sizes); offset_indices::accumulate_counts_to_offsets(face_offsets); MutableAttributeAccessor attributes_for_write = mesh.attributes_for_write(); diff --git a/source/blender/editors/object/object_remesh.cc b/source/blender/editors/object/object_remesh.cc index 2b4b53be11e..685c0ccf473 100644 --- a/source/blender/editors/object/object_remesh.cc +++ b/source/blender/editors/object/object_remesh.cc @@ -160,13 +160,13 @@ static wmOperatorStatus voxel_remesh_exec(bContext *C, wmOperator *op) } BKE_mesh_nomain_to_mesh(new_mesh, mesh, ob); + /* Spatially organize the mesh after remesh. */ + blender::bke::mesh_apply_spatial_organization(*mesh); if (ob->mode == OB_MODE_SCULPT) { sculpt_paint::undo::geometry_end(*ob); BKE_sculptsession_free_pbvh(*ob); } - /* Spatially organize the mesh after remesh. */ - blender::bke::mesh_apply_spatial_organization(*static_cast(ob->data)); BKE_mesh_batch_cache_dirty_tag(static_cast(ob->data), BKE_MESH_BATCH_DIRTY_ALL); DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data); @@ -915,8 +915,6 @@ static void quadriflow_start_job(void *customdata, wmJobWorkerStatus *worker_sta sculpt_paint::undo::geometry_end(*ob); BKE_sculptsession_free_pbvh(*ob); } - /* Spatially organize the mesh after remesh. */ - blender::bke::mesh_apply_spatial_organization(*static_cast(ob->data)); BKE_mesh_batch_cache_dirty_tag(static_cast(ob->data), BKE_MESH_BATCH_DIRTY_ALL); worker_status->do_update = true; @@ -936,6 +934,8 @@ static void quadriflow_end_job(void *customdata) ReportList *reports = qj->worker_status->reports; switch (qj->status) { case QUADRIFLOW_STATUS_SUCCESS: + /* Spatially organize the mesh after remesh. */ + bke::mesh_apply_spatial_organization(*static_cast(ob->data)); DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); BKE_reportf(reports, RPT_INFO, "QuadriFlow: Remeshing completed"); break;