Hi.
I have a class which loads a .x file from file and when the .x file has been loaded, future meshes will be loaded from the memory location.
HRESULT Model::loadModel(char * model_name)
{
LPD3DXBUFFER pD3DXMtrlBuffer;
d_wNumOfMaterials = 0L;
if( FAILED( D3DXLoadMeshFromX( MultiCharToUniChar(model_name), D3DXMESH_SYSTEMMEM,
*g_pd3dDevice, NULL,
&pD3DXMtrlBuffer, NULL, &d_wNumOfMaterials,
&g_pMesh ) ) )
{
MessageBox(NULL, L"Failed to load mesh", L"Meshes.exe", MB_OK);
return E_FAIL;
}
...
return S_OK;
}
This works well, the problem is creating the mesh from the memory.
Lets say we load a model from the file and everything is stored properly inside the Model object. Now we create a new Model and call Model::loadModelFromMemory(Model* mod)
HRESULT Model::loadModelFromMemory(Model *mod)
{
LPD3DXBUFFER pD3DXMtrlBuffer;
d_wNumOfMaterials = 0L;
DWORD size = sizeof mod->g_pMesh;
if ( FAILED ( D3DXLoadMeshFromXInMemory(&(mod->g_pMesh), size, D3DXMESH_SYSTEMMEM,
*g_pd3dDevice, NULL,
&pD3DXMtrlBuffer, NULL, &d_wNumOfMaterials,
&g_pMesh ) ) )
{
MessageBox(NULL, L"Failed to load mesh", L"Meshes.exe", MB_OK);
return E_FAIL;
}
...
return S_OK;
}
The only thing D3DX tells me is "Bad magic number" when D3DXLoadMeshFromXInMemory is called.
Any help would be nice.
EDIT: Please remember to use 'source' tags in future.
[Edited by - jollyjeffers on October 12, 2007 7:11:26 AM]