.X File format and DirectX. Crashing, but why? Damn this world!
My program is crashing, but I really cannot pinpoint the problem. Tried commenting stuff out... debugging, etc...
By the way I was following the example that shipped with DirectX9 SDK on loading meshes.
I've pinpointed the problem to this section of code:
D3DXMATRIXA16 xmatWorld, xmatTemp1, xmatTemp2;
D3DXMatrixTranslation(&xmatWorld, 0.0f, -2.0f, 10.0f);
xmatWorld = xmatTemp1 * xmatTemp2 * xmatWorld;
for(DWORD i = 0; i < g_dwNumMaterials; i++)
g_pD3DDevice9->Present(NULL, NULL, NULL, NULL);
D3DXLoadMeshFromX("box.x", D3DXMESH_SYSTEMMEM, g_pD3DDevice9, NULL, &pD3DXMtrlBuffer, NULL, &g_dwNumMaterials, &g_pMesh);
D3DXMATERIAL *meshData = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();
g_pMeshMaterials = new D3DMATERIAL9[g_dwNumMaterials];
for (DWORD i = 0; i < g_dwNumMaterials; i++)
g_pMeshMaterials[i] = meshData[i].MatD3D;
g_pMeshMaterials[i].Ambient = g_pMeshMaterials[i].Diffuse;
The above line seems to be my problem. On the first pass through I get the following message but the program continues.
Second time through I get
First-chance exception in Test.exe (KERNEL32.DLL): 0xE06D7363: Microsoft C++ Exception.
and my program crashes. Anyone know what this means?
First-chance exception in Test.exe: 0xC0000005: Access Violation.
3DStudioMax7 using Plugin shipped with DirectX9 SDK
Microsoft Visual C++ 6.0
I'm befuddled as when I use the file shipped with the tutorial the program works perfectly fine. (tiger.x)
My box.x is just a simple cube, no materials.
Any ideas? I'm quite peeved at this troublesome problem :confused: