From 768c68f19b82c311fd67544f45e3edfd514b4075 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Tue, 2 Apr 2024 17:58:36 -0400 Subject: [PATCH] Fix #120179: Assert failure after sculpt trim operation Seems to be caused by c53e220aef. I didn't think our PBVH building would ever create a node with no triangles, but I guess I was wrong, since I checked and the PBVH is clearly being rebuilt after the trim operation, so it seems there isn't anything else weird going on here. Rather than trying to figure that out, I'll just add the empty check back here. Eventually we should completely replace the algorithm that creates the PBVH nodes anyway. --- source/blender/draw/intern/draw_pbvh.cc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/source/blender/draw/intern/draw_pbvh.cc b/source/blender/draw/intern/draw_pbvh.cc index ab458ee5513..1e179812a4b 100644 --- a/source/blender/draw/intern/draw_pbvh.cc +++ b/source/blender/draw/intern/draw_pbvh.cc @@ -1053,10 +1053,12 @@ struct PBVHBatches { void create_index_faces(const PBVH_GPU_Args &args) { - const bke::AttributeAccessor attributes = args.mesh->attributes(); - const VArray material_indices = *attributes.lookup_or_default( - "material_index", bke::AttrDomain::Face, 0); - material_index = material_indices[args.tri_faces[args.prim_indices.first()]]; + if (!args.prim_indices.is_empty()) { + const bke::AttributeAccessor attributes = args.mesh->attributes(); + const VArray material_indices = *attributes.lookup_or_default( + "material_index", bke::AttrDomain::Face, 0); + material_index = material_indices[args.tri_faces[args.prim_indices.first()]]; + } const Span edges = args.mesh->edges(); @@ -1144,8 +1146,10 @@ struct PBVHBatches { const BitGroupVector<> &grid_hidden = args.subdiv_ccg->grid_hidden; const Span grid_to_face_map = args.subdiv_ccg->grid_to_face_map; - material_index = material_indices[BKE_subdiv_ccg_grid_to_face_index( - *args.subdiv_ccg, args.grid_indices.first())]; + if (!args.grid_indices.is_empty()) { + material_index = material_indices[BKE_subdiv_ccg_grid_to_face_index( + *args.subdiv_ccg, args.grid_indices.first())]; + } needs_tri_index = true; int gridsize = args.ccg_key.grid_size;