   Parsing an .x file to PhysX
  Hi guys, i have just hit another problem (yes i know i should really have got used to this).Now i wasn't sure how to basically parse a loaded .x model, so i followed an example off a website. But, lo and behold, i hit an error (you know the one 0x00000005: Access Violation Reading location 0x000000000)Now, normally i can solve this as the 'thing' on the right that is referencing the pointer doesn't have a value. But this time i'm stumped.I'm sure that the LPD3DXMESH is going into the function because i actually put the mesh in there and i can select (in MSVS 2008) the member functions i want.Please helpJamesCobrasP.S. code below, the place where errors are created are annotated.std::vector<float> GetVertices(LPD3DXMESH g_pMesh){std::vector<float> vertices;/////////////////////////////////////////////////////////////////////////////DWORD stride =  D3DXGetFVFVertexSize(g_pMesh->GetFVF());///////It Breaks here////////////////////////////////////////////////////////////////////////////BYTE* vbptr = NULL;g_pMesh->LockVertexBuffer(0, (LPVOID*)&vbptr);int ii = -1;for(unsigned int i = 0; i < g_pMesh->GetNumVertices(); i++){ii++;D3DXVECTOR3* pos = (D3DXVECTOR3*)vbptr;vertices.push_back(pos->x);vertices.push_back(pos->y);vertices.push_back(pos->z);vbptr += stride;}g_pMesh->UnlockVertexBuffer();return vertices;}std::vector<short> GetIndices(LPD3DXMESHg_pMesh){//LPVOID* ppData;DWORD stride = sizeof(short);BYTE* ibptr = NULL;///////and It Breaks here if this function is first//////////////short* indices = new short[(g_pMesh)->GetNumFaces() * 3];///////////////////////////////////////////////////////////////////std::vector<short> copy;(g_pMesh)->LockIndexBuffer(0, (LPVOID*)&indices);for(unsigned int i = 0; i < (g_pMesh)->GetNumFaces() * 3; i++){copy.push_back(indices);}(g_pMesh)->UnlockIndexBuffer();return copy;}These two functions slot into the top of this functionNxActor* GenTriangleMesh(NxVec3 pos, std::vector<short> indices, std::vector<float> vertices ){int NumVerticies = vertices.size() / 3;int NumTriangles = indices.size() / 3;//Create pointer for verticesNxVec3* verts = new NxVec3[NumVerticies];int ii = -1;for(int i = 0; i < NumVerticies; i++){++ii;verts.x = vertices[ii];verts.y = vertices[++ii];verts.z = vertices[++ii];}//Create pointer for indicesNxU16 *tris = new NxU16[indices.size()];for(int i = indices.size() - 1; i >= 0; --i)tris = i;// Build physical modelNxTriangleMeshDesc TriMeshDesc;TriMeshDesc.numVertices = NumVerticies;TriMeshDesc.numTriangles = NumTriangles;TriMeshDesc.pointStrideBytes = sizeof(NxVec3);TriMeshDesc.triangleStrideBytes = 3*sizeof(NxU16);TriMeshDesc.points = verts;TriMeshDesc.triangles = tris;TriMeshDesc.flags = NX_MF_16_BIT_INDICES ;//| NX_MF_FLIPNORMALS  ;NxTriangleMeshShapeDesc ShapeDesc;NxInitCooking();// Cooking from memoryMemoryWriteBuffer buf;bool status = NxCookTriangleMesh(TriMeshDesc, buf);ShapeDesc.meshData = gPhysicsSDK->createTriangleMesh(MemoryReadBuffer(buf.data));NxActorDesc actorDesc;actorDesc.shapes.pushBack(&ShapeDesc);actorDesc.globalPose.t = pos;NxActor* act = gScene->createActor(actorDesc);delete[] verts;delete[] tris;return act;}
  I suggest reading This, and enabling the debug runtimes. The problem is that the g_pMesh pointer is null for some reason. Check where it's being set and make sure that the call is succeeding - in particular you MUST check the return value (With the SUCCEEDED() or FAILED() macro) for any D3D / D3DX function that returns a pointer (Or fills it in as a parameter), or you'll just end up with a solution that works on your PC but fails on others.   ;  Update:This is the function in the model class that i return my mesh from inline LPD3DXMESH MMesh(){return ModelMesh;}Enabled Dx debugging and had a look at the article(i have read it before).I don't think it is directly linked to directx but there is a problem there. Just trying to give as much info as needed.All help welcome.JamescobrasP.S. I'm still working on finding the problem.Also, if it makes any difference the original functions had the parameters as follows:std::vector<float> GetVertices(LPD3DXMESH *g_pMesh)std::vector<short> GetIndices(LPD3DXMESH*g_pMesh)// now has the parametersstd::vector<float> GetVertices(LPD3DXMESH g_pMesh)std::vector<short> GetIndices(LPD3DXMESHg_pMesh);  Where is g_pMesh created? It's a pointer to a mesh, but in all of the code you've posted so far, it's never actually assigned to point at anything.   ;  Now i hope this isn't a stupid answer but i thought that i needed that there as i was the place where my pointer to a mesh went.function in action:gTerrain = GenTriangleMesh(NxVec3(0,0,0),GetIndices(model.MMesh()),GetVertices(model.MMesh()));Does that answer your question?   ;  GetVertices() and GetIndices() take a mesh pointer as a parameter - where does that pointer come from? Where is the call to D3DXLoadMeshFrom*() or D3DXCreateMesh*()?EDIT: It helps if I read the post [smile]Ok, where ModelMesh initialised?   ;  Thanks Man you are fantastic. I'm really sorry for all of this, rookie mistake, i'm loading my mesh via animation so that model is not getting filled!! Sorry for wasting your time.But thanksJamescobrasOfficially, a massive idiot.   ;Quote:Original post by JamesCobrasThanks Man you are fantastic. I'm really sorry for all of this, rookie mistake, i'm loading my mesh via animation so that model is not getting filled!! Sorry for wasting your time.But thanksJamescobrasOfficially, a massive idiot.We all have off days [smile].As an aside, this is where assert()s are particularly useful; you can sanity check any pointers being passed around to make sure that they're not null.   ;  Well i hope this serves as a good example to people who are not debugging properly.   