For some reason it crashes on some meshes but not others, could my _VERTEX struct possibly be wrong? All I am looking for is the position but maybe the other things could come in handy later.
By crashing I mean that I loop through all the vertices and when I get up to about 90% of numVerts, pVerts suddenly is NULL.
I can load all the meshes in DirectX viewer, and they draw fine, so that is not the problem, but just when I try to get the vertices it seems like there is less vertices than what I get from m_pMesh->GetNumVertices(), therefore making pVerts equal zero at a certain point when I run out of vertices.
Can someone help me fix this?
Thanks,
r_bewick
#define FVF_VERTEX D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1struct _VERTEX{ D3DXVECTOR3 pos; // vertex position D3DXVECTOR3 norm; // vertex normal float tu; // texture coordinates float tv;};vector<D3DXVECTOR3> CMesh::GetVertices(){ vector<D3DXVECTOR3> vecVertices; _VERTEX* pVerts; m_pMesh->LockVertexBuffer(0,(void**)&pVerts); // get vertex count int numVerts=m_pMesh->GetNumVertices(); for (int i=0;i<numVerts;i++) { D3DXVECTOR3 vec3Vertice; vec3Vertice.x = pVerts->pos.x; vec3Vertice.y = pVerts->pos.y; vec3Vertice.z = pVerts->pos.z; vecVertices.push_back(vec3Vertice); // go to next vertex pVerts++; } // unlock the vertex buffer m_pMesh->UnlockVertexBuffer(); return vecVertices;}