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:
Code:
g_pD3DDevice9->BeginScene();
D3DXMATRIXA16 xmatWorld, xmatTemp1, xmatTemp2;
D3DXMatrixTranslation(&xmatWorld, 0.0f, -2.0f, 10.0f);
D3DXMatrixRotationY(&xmatTemp1, g_fRotAngleY);
D3DXMatrixRotationX(&xmatTemp2, g_fRotAngleX);
xmatWorld = xmatTemp1 * xmatTemp2 * xmatWorld;
g_pD3DDevice9->SetTransform(D3DTS_WORLD, &xmatWorld);
for(DWORD i = 0; i < g_dwNumMaterials; i++)
{
g_pD3DDevice9->SetMaterial(&g_pMeshMaterials[i]);
g_pMesh->DrawSubset(i);
}
g_pD3DDevice9->EndScene();
g_pD3DDevice9->Present(NULL, NULL, NULL, NULL);
Code:
bool LoadObjects()
{
LPD3DXBUFFER pD3DXMtrlBuffer;
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;
}
pD3DXMtrlBuffer->Release();
return true;
}
Code:
g_pMesh->DrawSubset(i);
The above line seems to be my problem. On the first pass through I get the following message but the program continues.
Code:
First-chance exception in Test.exe (KERNEL32.DLL): 0xE06D7363: Microsoft C++ Exception.
Second time through I get
Code:
First-chance exception in Test.exe: 0xC0000005: Access Violation.
and my program crashes. Anyone know what this means?
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