Hi all,
I am having a problem drawing meshing after loading them, and their materials/textures, from .X files.
Here is the code that loads the meshs:
Code:
static LPCWSTR XFileMeshes[] = {L"building1.x",L"table.x"};
static LPD3DXBUFFER MaterialBuffer[400];
static D3DXMATERIAL* TempMaterial;
static LPD3DXMESH *Meshes[2];
static int NumModels = 2;
static DWORD NumMaterials[400];
static D3DMATERIAL9* Material[400];
static LPDIRECT3DTEXTURE9* Texture[400];
static LPD3DXMESH meshTest;
static D3DMATERIAL9* meshMat;
static LPDIRECT3DTEXTURE9* meshText;
static DWORD meshNumMat;
static void LoadMeshes(LPDIRECT3DDEVICE9 d3ddev)
{
for(int i = 0; i < NumModels; i++)
{
Meshes[i] = new LPD3DXMESH;
//MessageBox(NULL, XFileMeshes[i], L"TEST", MB_OK);
if(FAILED(D3DXLoadMeshFromX(XFileMeshes[i], D3DXMESH_SYSTEMMEM, d3ddev, NULL, &MaterialBuffer[i], NULL, &NumMaterials[i], Meshes[i])))
MessageBox(NULL, L"Bad", L"Bad", MB_OK);
TempMaterial = (D3DXMATERIAL*)MaterialBuffer[i]->GetBufferPointer();
Material[i] = new D3DMATERIAL9[NumMaterials[i]];
Texture[i] = new LPDIRECT3DTEXTURE9[NumMaterials[i]];
for(DWORD p = 0; p < NumMaterials[i]; p++)
{
Material[i][p] = TempMaterial->MatD3D;
Material[i][p].Ambient = Material[i][p].Diffuse;
if(FAILED(D3DXCreateTextureFromFileA(d3ddev, TempMaterial[p].pTextureFilename, &Texture[i][p])))
Texture[i][p] = NULL;
}
}
When I call the DrawSubset function in my RenderFrame() function:
Code:
LPD3DXMESH TempMesh = (LPD3DXMESH)Meshes;
TempMesh[0].DrawSubset(0);
I get :
Unhandled exception at 0xabababab in Building1Explore.exe: 0xC0000005: Access violation.
I have looked and looked and am now going crazy not being able to see the problem.
Thanks very much,
Andy