Hi, when I try to read mesh file, I got error on the second loop, especially when the parser calls malloc for the second time. When I try different model with more mesh, e.g: 4 mesh, in mesh loop on count 3 it crashed. The VS tells me it can be heap corruption and there's "Critical error detected c0000374" in the output.
Here is the code:
for (int i = 0; i < iMesh; ++i) {
Mesh *pMesh = &pModel->pMesh[i];
fread(&pMesh->iTr, sizeof (int), 1, pIn);
pVe = (fVec3*)malloc(sizeof (fVec3) * pMesh->iTr);
pVn = (fVec3*)malloc(sizeof (fVec3) * pMesh->iTr);
pVt = (fVec2*)malloc(sizeof (fVec2) * pMesh->iTr);
pIndex = (fVec2*)malloc(sizeof (fVec2) * pMesh->iTr);
for (int j = 0; j < pMesh->iTr; ++j) {
//fread etc.
}
// OpenGL stuffs, buffer data
free(pVe);
free(pVt);
free(pVn);
}
Is this memory leak? What did I do wrong? Please help, I'm really struck here
I appreciate any reply, thanks before