createenumobject fails
Whenever I call CreateEnumObject, it fails. I believe my problem extends further than this, however. I found out that IDirectXFile interfaces had been delcared deprecated, so I attempeted to use newer functions, and I must have messed up with a casting, or be using the wrong interface or something like that. Here is all the code in my app that applies to it:
typedef struct meshstruct
{
char *name;
ID3DXMesh *meshobj;
ID3DXMesh *skinmesh;
ID3DXSkinInfo *skininfo;
DWORD numofmaterials;
D3DMATERIAL9 *materials;
LPDIRECT3DTEXTURE9 *textures;
meshstruct *next;
meshstruct()
{
name = NULL;
meshobj = NULL;
skinmesh = NULL;
skininfo = NULL;
numofmaterials = 0;
materials = NULL;
textures = NULL;
next = NULL;
}
~meshstruct()
{
delete [] name;
name = NULL;
meshobj->Release();
meshobj = NULL;
skinmesh->Release();
skinmesh = NULL;
skininfo->Release();
skininfo = NULL;
delete [] materials;
materials = NULL;
if(textures != NULL)
{
for(DWORD i = 0; i < numofmaterials; i++)
{
textures->Release();
textures = NULL;
}
delete [] textures;
textures = NULL;
}
delete next;
next = NULL;
}
} meshstruct;
typedef struct framestruct
{
char *name;
meshstruct *meshobj;
framestruct *sibframe;
framestruct *childframe;
framestruct()
{
name = NULL;
meshobj = NULL;
sibframe = NULL;
childframe = NULL;
}
~framestruct()
{
delete [] name;
name = NULL;
delete meshobj;
meshobj = NULL;
delete sibframe;
sibframe = NULL;
delete childframe;
childframe = NULL;
}
} framestruct;
framestruct *loadxfile(char* filename, framestruct* savedframe);
void parsexfiledata(IDirectXFileData *dataobj, framestruct *parentframe);
void drawframe(framestruct *frametodraw);
framestruct *loadxfile(char* filename, framestruct* savedframe)
{
IDirectXFile *file = NULL;
IDirectXFileEnumObject *enumobj = NULL;
IDirectXFileData *data = NULL;
framestruct *frame;
DirectXFileCreate(&file);
file->RegisterTemplates((LPVOID)D3DRM_XTEMPLATES, D3DRM_XTEMPLATE_BYTES);
HRESULT reshand = file->CreateEnumObject((LPVOID)filename, DXFILELOAD_FROMFILE, &enumobj); // I have managed to trace the error to here.
// It may extend further, however I read about IDirectXFile interfaces being deprecated, and this is
// probably linked to that in some way.
if(reshand = DXFILEERR_BADVALUE)
{
reshand = NULL;
}
frame = new framestruct();
while(SUCCEEDED(enumobj->GetNextDataObject(&data)))
{
parsexfiledata(data, frame);
data->Release();
data = NULL;
}
enumobj->Release();
enumobj = NULL;
file->Release();
file = NULL;
savedframe = frame;
return frame;
}
void parsexfiledata(IDirectXFileData *dataobj, framestruct *parentframe)
{
IDirectXFileObject *subobj = NULL;
IDirectXFileData *subdata = NULL;
IDirectXFileDataReference *dataref = NULL;
ID3DXBuffer *adjacency = NULL;
const GUID *type = NULL;
char *name = NULL;
DWORD sizeofname;
framestruct *frame = NULL;
framestruct *subframe = NULL;
meshstruct *mesh = NULL;
ID3DXBuffer *materialbuffer = NULL;
D3DXMATERIAL *materials = NULL;
DWORD i;
dataobj->GetType(&type);
dataobj->GetName(NULL, &sizeofname);
if(sizeofname)
{
name = new char[sizeofname];
dataobj->GetName(name, &sizeofname);
}
if(name == NULL)
{
name = new char[12];
strcpy(name, "defaultname");
}
subframe = parentframe;
if(*type == TID_D3DRMFrame)
{
frame = new framestruct();
frame->name = name;
name = NULL;
frame->sibframe = parentframe->childframe;
parentframe->childframe = frame;
subframe = frame;
}
if(*type == TID_D3DRMMesh)
{
mesh = new meshstruct();
mesh->name = name;
name = NULL;
D3DXLoadSkinMeshFromXof((LPD3DXFILEDATA)dataobj, 0, d3ddeviceptr, &adjacency, &materialbuffer, NULL, &mesh->numofmaterials, &mesh->skininfo, &mesh->meshobj);
adjacency->Release();
adjacency = NULL;
if(mesh->skininfo != NULL && mesh->skininfo->GetNumBones() > 0)
mesh->meshobj->CloneMeshFVF(0, mesh->meshobj->GetFVF(), d3ddeviceptr, &mesh->skinmesh);
if(!mesh->numofmaterials)
{
mesh->materials = new D3DMATERIAL9[1];
mesh->textures = new LPDIRECT3DTEXTURE9[1];
ZeroMemory(mesh->materials, sizeof(D3DMATERIAL9));
mesh->materials[0].Diffuse.r = 1.0f;
mesh->materials[0].Diffuse.g = 1.0f;
mesh->materials[0].Diffuse.b = 1.0f;
mesh->materials[0].Diffuse.a = 1.0f;
mesh->materials[0].Ambient = mesh->materials[0].Diffuse;
mesh->materials[0].Specular = mesh->materials[0].Diffuse;
mesh->textures[0] = NULL;
mesh->numofmaterials = 1;
}
else
{
materials = (D3DXMATERIAL*)materialbuffer->GetBufferPointer();
mesh->materials = new D3DMATERIAL9[mesh->numofmaterials];
mesh->textures = new LPDIRECT3DTEXTURE9[mesh->numofmaterials];
for(i = 0; i < mesh->numofmaterials; i++)
{
mesh->materials = materials.MatD3D;
mesh->materials.Ambient = mesh->materials.Diffuse;
if(FAILED(D3DXCreateTextureFromFileA(d3ddeviceptr, materials.pTextureFilename, &mesh->textures)))
// I am not sure about calling D3DXCreateTextureFromFileA instead of
//D3DXCreateTextureFromFile.
mesh->textures = NULL;
}
}
materialbuffer->Release();
materialbuffer = NULL;
mesh->next = parentframe->meshobj;
parentframe->meshobj = mesh;
}
if(*type == TID_D3DRMAnimationSet || *type == TID_D3DRMAnimation || *type == TID_D3DRMAnimationKey)
{
delete [] name;
return;
}
delete [] name;
while(SUCCEEDED(dataobj->GetNextObject(&subobj)))
{
if(SUCCEEDED(subobj->QueryInterface(IID_IDirectXFileDataReference, (void**)dataref)))
{
if(SUCCEEDED(dataref->Resolve(&subdata)))
{
parsexfiledata(subdata, subframe);
subdata->Release();
subdata = NULL;
}
dataref->Release();
dataref = NULL;
}
if(SUCCEEDED(subobj->QueryInterface(IID_IDirectXFileData, (void**)subdata)))
{
parsexfiledata(subdata, subframe);
subdata->Release();
subdata = NULL;
}
subobj->Release();
subobj = NULL;
}
return;
}
void drawframe(framestruct *frametodraw)
{
meshstruct *mesh;
D3DXMATRIX *matrices = NULL;
DWORD i;
ID3DXMesh *meshtodraw;
if(frametodraw == NULL)
return;
if((mesh = frametodraw->meshobj) != NULL)
{
meshtodraw = mesh->meshobj;
if(mesh->skinmesh != NULL && mesh->skininfo != NULL)
{
matrices = new D3DXMATRIX[mesh->skininfo->GetNumBones()];
for(i=0; i < mesh->skininfo->GetNumBones(); i++)
D3DXMatrixIdentity(&matrices);
void *source;
void *destination;
mesh->meshobj->LockVertexBuffer(0, (void**)&source);
mesh->meshobj->LockVertexBuffer(0, (void**)&destination);
mesh->skininfo->UpdateSkinnedMesh(matrices, NULL, source, destination);
mesh->skinmesh->UnlockVertexBuffer();
mesh->meshobj->UnlockVertexBuffer();
meshtodraw = mesh->skinmesh;
}
for(i = 0; i < mesh->numofmaterials; i++)
{
d3ddeviceptr->SetMaterial(&mesh->materials);
d3ddeviceptr->SetTexture(0, mesh->textures);
meshtodraw->DrawSubset(i);
}
delete [] matrices;
matrices = NULL;
mesh = mesh->next;
}
drawframe(frametodraw->childframe);
drawframe(frametodraw->sibframe);
}
and here is the code that actually loads the mesh:
loadxfile(
"fightermodel1.x", &testframe);also, here is the code that displays it, although I know the error occured earlier, I am including it just to be thorough:
drawframe(&testframe);
thanks alot for any help.

