Original Post
I have a problem loading a couple of .x file. The number of materials returned by D3DXLoadMeshFromX is not the same as the number of attributes after optimizing the mesh. This makes it impossible to map textures to attributes. I initially thought it was a problem with the file itself but DirectX Viewer and my format conversion tools manage to display the textures correctly. What could DX Viewer be doing differently / what am I doing wrong? Relavent portion of mesh loading code: This works just fine for several other .x files.
ID3DXMesh* pMesh = 0;
ID3DXBuffer* adjBuffer = 0;
ID3DXBuffer* mtrlBuffer = 0;
ID3DXBuffer* effectInstances = 0;
DWORD numMtrls = 0;
DWORD attrSize = 0;
//Load From File
D3DXLoadMeshFromX(FileName.c_str(), D3DXMESH_MANAGED, D3D9NullRaster, &adjBuffer, &mtrlBuffer, &effectInstances, &numMtrls, &pMesh)
//Sort by attribute
pMesh->OptimizeInplace(D3DXMESHOPT_ATTRSORT, (DWORD*)(adjBuffer->GetBufferPointer()), 0, 0, 0)
//Get number of attributes
pMesh->GetAttributeTable(0, &attrSize);
//attrSize != numMtrls???