failed mesh loading

I can't seem to figure out why this function fails.

Here is the structure definition(I know it has some unneccessary things in it, I am going to remove them):

typedefstruct meshstruct

{

char *name;

ID3DXMesh *meshobj;

ID3DXMesh *skinmesh;

ID3DXSkinInfo *skininfo;

DWORD numofmaterials;

D3DMATERIAL9 *materials;

LPDIRECT3DTEXTURE9 *textures;

meshstruct *next;

} meshstruct;

I excluded the constructor and destructors, as I thought they were unneccessary. I would be happy to post them if you would like.

here is the actual function:

bool loadxfilesimple(meshstruct* mesh, LPCWSTR filename)

{

LPD3DXBUFFER matbuff = NULL;// is 0xcccccccc

DWORD nummats;

if(FAILED(D3DXLoadMeshFromX(filename, D3DXMESH_SYSTEMMEM, d3ddeviceptr, NULL, &matbuff, NULL, &nummats, &mesh->meshobj)))

{

sayfailedtoload =true;

returnfalse;

}

else

{

D3DXMATERIAL* matbufftwo = (D3DXMATERIAL*)matbuff->GetBufferPointer();

if(&matbufftwo == NULL)

{

nummats = 1;

D3DMATERIAL9 meshmats[1];

meshmats[0].Diffuse.r = 1.0f;

meshmats[0].Diffuse.g = 1.0f;

meshmats[0].Diffuse.b = 1.0f;

meshmats[0].Diffuse.a = 1.0f;

meshmats[0].Ambient = meshmats->Diffuse;

LPDIRECT3DTEXTURE9 meshtexts[1];

meshtexts[0] = NULL;

mesh->materials = meshmats;

mesh->textures = meshtexts;

mesh->numofmaterials = nummats;

}

else

{

DWORD i = 0;

D3DMATERIAL9 *meshmatsloaded =new D3DMATERIAL9[nummats];

LPDIRECT3DTEXTURE9* meshtextsloaded =new LPDIRECT3DTEXTURE9[nummats];

while(i < nummats)

{

meshmatsloadedIdea = matbufftwo->MatD3D;

if(FAILED(D3DXCreateTextureFromFileA(d3ddeviceptr, matbufftwo->pTextureFilename, &meshtextsloadedIdea)))

meshtextsloadedIdea = NULL;

i++;

}

mesh->materials = meshmatsloaded;

mesh->textures = meshtextsloaded;

mesh->numofmaterials = nummats;

}

}

returntrue;

}

and, last but not least, here is where I instanced the mesh structure and called the function:

meshstruct testmesh; // note that this is global

loadxfilesimple(&testmesh, L"fightermodel1.x")

Please, someone tell me what I am doing wrong. thanks for all your help.

[3823 byte] By [programmingisfun] at [2007-12-27]
# 1
I don't believe it! I am an idiot! I forgot the ..\\ at the beginning of the filename! No wonder it was failing!
programmingisfun at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: Graphics...