Archived

This topic is now archived and is closed to further replies.

Problems with DrawIndexedPrimitive

This topic is 5331 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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[i] ); m_pd3dDevice->SetTexture( 1, Meshes[Whichfile]->m_ppBumpTextures[i] ); hr=m_pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, Meshes[Whichfile]->pAttribTable[i].VertexStart,Meshes[Whichfile]->pAttribTable[i].VertexCount,Meshes[Whichfile]->pAttribTable[i].FaceStart*3,Meshes[Whichfile]->pAttribTable[i].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;im_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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites