Problems with DrawIndexedPrimitive

Started by
1 comment, last by laeuchli 20 years, 11 months ago
Dear All, I''m having some problems using DrawIndexedPrimitive. I''ve writen 2 functions for loading and rendering X files. It works for the smaller X files, but for the bigger ones, I get the a error message in the debug spew, saying Direct3D8: (ERROR) :Index stream does not have required number of indices. DrawIndexedPrimitive failed. If I use retail directx, my computer just reboots(undering WinXP too, which is disturbing.). Below is my rendering code: void DXCore::RenderXFile(int Whichfile) { hr=m_pd3dDevice->SetStreamSource(0,Meshes[Whichfile]->ppVB,sizeof(CUSTOMVERTEX)); hr=m_pd3dDevice->SetIndices( Meshes[Whichfile]->ppIB, 0 ); for( UINT i = 0; i < Meshes[Whichfile]->m_dwNumMaterials; i++ ) { m_pd3dDevice->SetMaterial( &Meshes[Whichfile]->m_pMaterials.MatD3D ); m_pd3dDevice->SetTexture( 0, Meshes[Whichfile]->m_ppTextures ); m_pd3dDevice->SetTexture( 1, Meshes[Whichfile]->m_ppBumpTextures ); hr=m_pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, Meshes[Whichfile]->pAttribTable.VertexStart,Meshes[Whichfile]->pAttribTable.VertexCount,Meshes[Whichfile]->pAttribTable.FaceStart*3,Meshes[Whichfile]->pAttribTable.FaceCount); if(hr!=D3D_OK) { #ifdef DEBUG MessageBox(0,"Error Rendering X File","Error",MB_OK); #endif } } } This is my loading code: int DXCore::LoadXFile(char *Filename) { LPD3DXBUFFER m_pbufMaterials; LPD3DXBUFFER m_pbufAdjacency; int index=0; for(int i=0;i<MAXMESHES;i++) { if(FreeMeshNumbers==true) { index=i; FreeMeshNumbers=false; i=MAXMESHES+1; } } Meshes[index]=new MeshInfo; hr = D3DXLoadMeshFromX( Filename, D3DXMESH_MANAGED, m_pd3dDevice, &m_pbufAdjacency, &m_pbufMaterials, &Meshes[index]->m_dwNumMaterials, &Meshes[index]->m_pMesh ); if( FAILED(hr) ) MessageBox(0,"Failed to load X file",Filename,MB_OK); ID3DXMesh *newMesh; Meshes[index]->m_pMesh->CloneMeshFVF(0,D3DFVF_CUSTOMVERTEX,m_pd3dDevice,&newMesh); Meshes[index]->m_pMesh->Release(); Meshes[index]->m_pMesh=newMesh; DWORD *pAdj=new DWORD[Meshes[index]->m_pMesh->GetNumFaces()*3]; Meshes[index]->m_pMesh->GenerateAdjacency(0.0f,pAdj); hr=Meshes[index]->m_pMesh->OptimizeInplace(D3DXMESHOPT_ATTRSORT,pAdj,NULL,NULL,NULL); unsigned long atribnum; Meshes[index]->m_pMesh->GetAttributeTable( NULL, &atribnum ); Meshes[index]->pAttribTable=new D3DXATTRIBUTERANGE[atribnum]; Meshes[index]->m_pMesh->GetAttributeTable( Meshes[index]->pAttribTable, &atribnum ); Meshes[index]->m_pMesh->GetVertexBuffer(&Meshes[index]->ppVB); Meshes[index]->m_pMesh->GetIndexBuffer(&Meshes[index]->ppIB); ……Rest of function, loads the textures Does anyone see what I could be doing wrong? Does anyone have any suggestions for debuging? This is driving me nuts :-(. Jesse </i>
Advertisement
Hi,
you have probably solved this already, but anyway.
I hade the same problem (the reset is _very_ annoying) and the reason was that my x-file listed 6 materials but only 5 were assigned to faces so when i iterated on the materialcount and got to the last one i got garbage values for
m_attributes[imat].VertexStart and so on.

So i just changed the iterator to loop on number of attributes instead and it worked fine.


Regards,

Aron j
www.dice.se

[edited by - aronj on May 11, 2003 5:48:30 PM]
yeap, that was my problem too :-).
Jesse

This topic is closed to new replies.

Advertisement