Re: Excessive "fd" bytes at its tail of heap allocation
Hi Igor,
Thanks for your help!
here is the entire method.. pls take a look
With a couple of changes,
[code]
HRESULT CMesh::LoadMesh(const char *szfilename)
{
char szPath[1024];
CAllocateHierarchy Alloc;
PBYTE pMappedFileBase = NULL;
// unload these functions to a dll
::GetModuleFileNameA(NULL, szPath, sizeof(szPath));
strcat (szPath, szfilename);
FILE *fp = fopen (szPath, "rb");
if (fp == NULL)
OutputDebugStringA("File open error\n");
__int64 si = FileSize64(szPath);
int actlen = si-4;
std::vector<BYTE> v(actlen);
pMappedFileBase = &v[0];
memset (pMappedFileBase, 0, actlen);
fseek(fp, 4, SEEK_SET);
fread(pMappedFileBase, sizeof(BYTE), actlen, fp);
int size_template = sizeof(template_bin);
int j = actlen+size_template;
std::vector<BYTE> v2(j);
PBYTE pBin = &v2[0];
int x;
for (x = 0; x < size_template; x++)
{
pBin[x] = template_bin[x];
}
int i = 0;
for (; x < j;x++,i++)
{
pBin[x] = pMappedFileBase[i];
}
assert(x == j);
HRESULT hr = S_OK;
// Build a new parser?
hr = D3DXLoadMeshHierarchyFromXInMemory((LPCVOID) pBin, j,
D3DXMESH_MANAGED, m_pDevice, &Alloc,
NULL, (LPD3DXFRAME*)&m_pFrameRoot, &m_pAnimController);
if (FAILED(hr))
{
MessageBoxA(NULL, "Can't load mesh", "Error", MB_OK);
}
fclose(fp);
return hr;
}
[/code]
Thanks
Jack