Fix T103559: Check for no-face object for particle baking

Meshes spawning particles from faces with with UV's/Vertex-colors but no
faces would crash de-referencing a NULL pointer.

Resolve by adding a check for this case and an assertion if CD_MFACE is
NULL when the mesh has polygons.

Ref D16947
This commit is contained in:
Sibo Van Gool 2023-01-16 11:06:01 +11:00 committed by Campbell Barton
parent 28db19433e
commit b038662887
Notes: blender-bot 2023-02-13 13:41:34 +01:00
Referenced by issue #104278, Crash in geometrynode doversion code when opening Sprite production file
Referenced by issue #103559, Crash on baking path particles when mesh don't have any faces
1 changed files with 10 additions and 0 deletions

View File

@ -311,6 +311,11 @@ static void particle_calculate_parent_uvs(ParticleSystem *psys,
}
if (!ELEM(num, DMCACHE_NOTFOUND, DMCACHE_ISCHILD)) {
const MFace *mfaces = CustomData_get_layer(&psmd->mesh_final->fdata, CD_MFACE);
if (UNLIKELY(mfaces == NULL)) {
BLI_assert_msg(psmd->mesh_final->totpoly == 0,
"A mesh with polygons should always have a generated 'CD_MFACE' layer!");
return;
}
const MFace *mface = &mfaces[num];
for (int j = 0; j < num_uv_layers; j++) {
psys_interpolate_uvs(mtfaces[j] + num, mface->v4, particle->fuv, r_uv[j]);
@ -341,6 +346,11 @@ static void particle_calculate_parent_mcol(ParticleSystem *psys,
}
if (!ELEM(num, DMCACHE_NOTFOUND, DMCACHE_ISCHILD)) {
const MFace *mfaces = CustomData_get_layer(&psmd->mesh_final->fdata, CD_MFACE);
if (UNLIKELY(mfaces == NULL)) {
BLI_assert_msg(psmd->mesh_final->totpoly == 0,
"A mesh with polygons should always have a generated 'CD_MFACE' layer!");
return;
}
const MFace *mface = &mfaces[num];
for (int j = 0; j < num_col_layers; j++) {
/* CustomDataLayer CD_MCOL has 4 structs per face. */