Hello,
While attempting to retrieve the 3 vertices for each polygon in a scene I always get a SIGSEGV on the indicated line. How does one correctly retrievev such information ?
Code:
VERTTYPE vtPlane[4]; // 4 coefs in a*x +b*y +c*z + d = 0
VERTTYPE vtFace[3][3]; // 3 points each having 3 coords
unsigned short usI[3]; // indices in the vertices array for one point
bool bExistentPlane = false;
short i = 0;
__bInterleaved = scene.pMesh[0].pInterleaved != NULL;
for (unsigned int nm = 0; nm < scene.nNumMesh; nm++) // each mesh in the scene
{
SPODMesh& currentMesh = scene.pMesh[nm];
if (currentMesh.ePrimitiveType == ePODLines)
continue; // we do not fear intersection with .. lines
for (unsigned int nf = 0; nf < currentMesh.nNumFaces; nf++) // each poly in the mesh
{
CPODData& currentFaces = currentMesh.sFaces;
// assuming nStride = 2 and the type is indeed unsigned short;
if (currentFaces.eType != EPODDataUnsignedShort)
return false;
// same for the vertex array - assume floats
if (currentMesh.sVertex.eType != EPODDataFloat)
return false;
for (char nv = 0; nv < 3; nv++) // for all 3 vertices of this face
{
usI[0] = ((unsigned short*) currentFaces.pData)[nf + nv*3 + 0];
usI[1] = ((unsigned short*) currentFaces.pData)[nf + nv*3 + 1];
usI[2] = ((unsigned short*) currentFaces.pData)[nf + nv*3 + 2];
// line below fails with SIGSEGV as the usI[] contains trash
vtFace[nv][0] = __bInterleaved ? ((float*) currentMesh.pInterleaved)[usI[0]] : ((float*) currentMesh.sVertex.pData)[usI[0]];
// I have noticed it fails for the same nv = 2 (3rd vertex), nf = 0 (first face) but nm can be anything (?). Noticed this behaviour for the 10th, 9th and 7th meshes (nm = mesh number). Never worked for all meshes without error.
vtFace[nv][1] = __bInterleaved ? ((float*) currentMesh.pInterleaved)[usI[1]] : ((float*) currentMesh.sVertex.pData)[usI[1]];
vtFace[nv][2] = __bInterleaved ? ((float*) currentMesh.pInterleaved)[usI[2]] : ((float*) currentMesh.sVertex.pData)[usI[2]];
}
...
...
Thank you