Okay where do I begin. Basically I am reading stuff in from a file. I dont' want to post all of the structures, but the following works (seemingly) perfectly:
Code:
for(int index = 0; index < pHeader.numMeshes; index++) {
fseek(filePtr, offset, SEEK_SET);
fread(&pMesh, sizeof(Mesh), 1, filePtr);
Skin *pSkin = new Skin[pMesh.numSkins];
Face *pTriangle = new Face[pMesh.numTriangles];
TexCoord *pTexCoord = new TexCoord[pMesh.numVertices];
Triangle *pVertices = new Triangle[pMesh.numVertices * pMesh.numMeshFrames];
fread(pSkin, sizeof(Skin), pMesh.numSkins, filePtr);
fseek(filePtr, offset + pMesh.triStart, SEEK_SET);
fread(pTriangle, sizeof(Face), pMesh.numTriangles, filePtr);
fseek(filePtr, offset + pMesh.uvStart, SEEK_SET);
fread(pTexCoord, sizeof(TexCoord), pMesh.numVertices, filePtr);
fseek(filePtr, offset + pMesh.vertexStart, SEEK_SET);
fread(pVertices, sizeof(Triangle), pMesh.numVertices * pMesh.numMeshFrames, filePtr);
delete[] pSkin;
delete[] pTriangle;
delete[] pTexCoord;
delete[] pVertices;
location++;
offset += pMesh.meshSize;
}
Now, whenever I add this line of code into the loop the 'data' that is being read turns into garbage, i.e instead of getting sub-50 values for the specific file I am trying to read in, the range goes up into the thousands (could be reading hexadecimal memory addresses perhaps?)
m1.theObjects[location].pVertices = new CVector3[pMesh.numVertices];
m1 is a Model structure, each Model structures has a vector of type Object (NOTvector of pointers!), each Object has among other things an array of Vertices that must be allocated at run time.
Here are those data structures
//MESH
struct object {
CVector3 * pVertices; //ALL OF THE VERTICES IN THE MODEL
CVector2 * pUV; //TEXTURE COORDINATES ARE TOTALLY SWEET
char Name[256]; //I DUNNO WE MAY WANT SOME KIND OF DESCRIPTION
};
struct model {
vector<object> theObjects; //ARRAY OF MESHES
};
I dont know if I've posted enough for you to help me, but I didn't want to over do this. Anyway to sum it up allocating memory for the pVertices is what is screwing me up. When I don't allocate memory for the vertices and just read in stuff from the file and check it, it is all good.
Thanks if you can help me. I suck with allocating memory
EDIT:
And yes I know pHeader and pMesh arent pointers