Fix: BMesh to Mesh conversion does not create all necessary layers

Even meshes without any faces must have MPoly and MLoop layers, etc.
This caused a crash in the extrude node when the edit mesh had no faces
(see T101208). Issue with f94130c94b.
This commit is contained in:
Hans Goudey 2022-09-20 14:34:12 -05:00
parent 9df0d20957
commit 01ed08690a
Notes: blender-bot 2023-02-14 10:14:07 +01:00
Referenced by issue #101603, Crash with Extrude Node with one vertex
1 changed files with 8 additions and 24 deletions

View File

@ -980,30 +980,14 @@ void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMesh
CustomData_copy_mesh_to_bmesh(&bm->pdata, &me->pdata, mask.pmask, CD_SET_DEFAULT, me->totpoly);
}
MutableSpan<MVert> mvert;
MutableSpan<MEdge> medge;
MutableSpan<MPoly> mpoly;
MutableSpan<MLoop> mloop;
if (me->totvert > 0) {
mvert = {static_cast<MVert *>(
CustomData_add_layer(&me->vdata, CD_MVERT, CD_SET_DEFAULT, nullptr, me->totvert)),
me->totvert};
}
if (me->totedge > 0) {
medge = {static_cast<MEdge *>(
CustomData_add_layer(&me->edata, CD_MEDGE, CD_SET_DEFAULT, nullptr, me->totedge)),
me->totedge};
}
if (me->totpoly > 0) {
mpoly = {static_cast<MPoly *>(
CustomData_add_layer(&me->pdata, CD_MPOLY, CD_SET_DEFAULT, nullptr, me->totpoly)),
me->totpoly};
}
if (me->totloop > 0) {
mloop = {static_cast<MLoop *>(
CustomData_add_layer(&me->ldata, CD_MLOOP, CD_SET_DEFAULT, nullptr, me->totloop)),
me->totloop};
}
CustomData_add_layer(&me->vdata, CD_MVERT, CD_SET_DEFAULT, nullptr, me->totvert);
CustomData_add_layer(&me->edata, CD_MEDGE, CD_SET_DEFAULT, nullptr, me->totedge);
CustomData_add_layer(&me->ldata, CD_MLOOP, CD_SET_DEFAULT, nullptr, me->totloop);
CustomData_add_layer(&me->pdata, CD_MPOLY, CD_SET_DEFAULT, nullptr, me->totpoly);
MutableSpan<MVert> mvert = me->verts_for_write();
MutableSpan<MEdge> medge = me->edges_for_write();
MutableSpan<MPoly> mpoly = me->polys_for_write();
MutableSpan<MLoop> mloop = me->loops_for_write();
bool need_hide_vert = false;
bool need_hide_edge = false;