Fix T89393: crash when selecting edges when geometry nodes has "on cage" turned on

The core problem is that the geometry nodes modifier sometimes support
"mapping" (i.e. it remembers which new vertices correspond to edit mode
vertices) and sometimes it does not, depending on what the nodes are doing.
Also see rB07ce9910f7cc.

The solution here is that the fallback case in `BKE_mesh_foreach_mapped_edge`
does not call the callback with "invalid" indices.

Differential Revision: https://developer.blender.org/D12007
This commit is contained in:
Jacques Lucke 2021-07-23 16:15:18 +02:00
parent 239a74a130
commit eb43477851
Notes: blender-bot 2023-02-14 08:10:06 +01:00
Referenced by issue #89393, Crash blender in edit mode(edges) if geometry node have "On cage"
3 changed files with 12 additions and 5 deletions

View File

@ -41,6 +41,7 @@ void BKE_mesh_foreach_mapped_vert(struct Mesh *mesh,
MeshForeachFlag flag);
void BKE_mesh_foreach_mapped_edge(
struct Mesh *mesh,
int tot_edges,
void (*func)(void *userData, int index, const float v0co[3], const float v1co[3]),
void *userData);
void BKE_mesh_foreach_mapped_loop(struct Mesh *mesh,

View File

@ -95,9 +95,14 @@ void BKE_mesh_foreach_mapped_vert(Mesh *mesh,
}
}
/* Copied from cdDM_foreachMappedEdge */
/**
* Copied from #cdDM_foreachMappedEdge.
* \param tot_edges: Number of original edges. Used to avoid calling the callback with invalid
* edge indices.
*/
void BKE_mesh_foreach_mapped_edge(
Mesh *mesh,
const int tot_edges,
void (*func)(void *userData, int index, const float v0co[3], const float v1co[3]),
void *userData)
{
@ -138,7 +143,7 @@ void BKE_mesh_foreach_mapped_edge(
func(userData, orig, mv[med->v1].co, mv[med->v2].co);
}
}
else {
else if (mesh->totedge == tot_edges) {
for (int i = 0; i < mesh->totedge; i++, med++) {
func(userData, i, mv[med->v1].co, mv[med->v2].co);
}

View File

@ -439,7 +439,7 @@ void mesh_foreachScreenEdge(ViewContext *vc,
}
BM_mesh_elem_table_ensure(vc->em->bm, BM_EDGE);
BKE_mesh_foreach_mapped_edge(me, mesh_foreachScreenEdge__mapFunc, &data);
BKE_mesh_foreach_mapped_edge(me, vc->em->bm->totedge, mesh_foreachScreenEdge__mapFunc, &data);
}
/** \} */
@ -529,10 +529,11 @@ void mesh_foreachScreenEdge_clip_bb_segment(ViewContext *vc,
if ((clip_flag & V3D_PROJ_TEST_CLIP_BB) && (vc->rv3d->clipbb != NULL)) {
ED_view3d_clipping_local(vc->rv3d, vc->obedit->obmat); /* for local clipping lookups. */
BKE_mesh_foreach_mapped_edge(me, mesh_foreachScreenEdge_clip_bb_segment__mapFunc, &data);
BKE_mesh_foreach_mapped_edge(
me, vc->em->bm->totedge, mesh_foreachScreenEdge_clip_bb_segment__mapFunc, &data);
}
else {
BKE_mesh_foreach_mapped_edge(me, mesh_foreachScreenEdge__mapFunc, &data);
BKE_mesh_foreach_mapped_edge(me, vc->em->bm->totedge, mesh_foreachScreenEdge__mapFunc, &data);
}
}