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
This commit is contained in:
Namit Bhutani
2025-07-16 14:27:18 +02:00
committed by Hans Goudey
parent 9e1168bdfb
commit 8602f893ed
2 changed files with 7 additions and 6 deletions

View File

@@ -886,8 +886,9 @@ void mesh_apply_spatial_organization(Mesh &mesh)
corner_verts.copy_from(new_corner_verts);
MutableSpan<int> face_offsets = mesh.face_offsets_for_write();
MutableSpan<int> face_sizes_view = face_offsets.take_front(new_face_order.size());
gather_group_sizes(old_faces, new_face_order, face_sizes_view);
Vector<int> 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();

View File

@@ -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<Mesh *>(ob->data));
BKE_mesh_batch_cache_dirty_tag(static_cast<Mesh *>(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<Mesh *>(ob->data));
BKE_mesh_batch_cache_dirty_tag(static_cast<Mesh *>(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<Mesh *>(ob->data));
DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
BKE_reportf(reports, RPT_INFO, "QuadriFlow: Remeshing completed");
break;