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.
Differential D16947
Fix T103559: Check for no-face object for particle baking Authored by Sibo Van Gool (SiboVG) on Jan 8 2023, 4:23 PM.
Details 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.
Diff Detail
Event TimelineComment Actions Hi, thanks for the patch. Comment Actions Hey @Pratik Borhade (PratikPB2123), thanks for taking a look at it! Do you mean to check for a NULL face still inside particle_calculate_parent_uvs, but before MFace *mface = &mfaces[num];? Or do you mean to check for it at the initialization of mtfaces[i] = (const MTFace *)CustomData_get_layer_n(
&psmd->mesh_final->fdata, CD_MTFACE, i);and mtfaces[j] = (const MTFace *)CustomData_get_layer_n(
&psmd->mesh_final->fdata, CD_MTFACE, j);? Comment Actions That CD_MFACE is missing seems like a bug, did you check on why MFace's are missing. If the MFace's cant be ensured, checking for null is better than crashing, but in that case the check should be on mfaces, before entering the loop not on mface as a null check on this value will only work if it's the first item in the array. Comment Actions
@Campbell Barton (campbellbarton) hi, in uploaded file, mesh don't really have any faces: T103559#1468314 Comment Actions In this case, an early return could be used in the case of a mesh without polygons/faces as there is no reason to loop over all UV layers and check for MFace's each iteration. In this case though it would be better to assert that the mesh has no polygons, as this could silently hide the case that the CD_MFACE layer is not being generates from CD_MPOLY as it should be.
Comment Actions Thanks for updating. Could you also update the patch description to match with the current diff (explain why this change is done)? Comment Actions Apply the fix for Vertex Colors as well as this crash also occurs with vertex colors if they are found. | ||||||||||