   DrawIndexedPrimitive fails
  I am trying to obtain realistic reflections through dynamic cube maps.In the rendering chunk, I do (pseudo code):// ----------------------------------------// render the cube mapbegin cube maprender the scene for each face of the cubeend cube map// render the scenebegin scenerender the scene (using the cube map) from the point of view of the cameraend scenepresent// ---------------------------------------- if I run the application with DirectX9 in debug mode, it crashes on a DrawIndexedPrimitive instruction and the error message is:Direct3D9: (ERROR) :Index stream does not have required number of indices. DrawIndexedPrimitive failed. If I render only the cube map, the error does not show up and the cube map is correct.If I render only the scene without cube map, the error does not happen.Any idea?thanks   
  You don't have enough indices in your index buffer, based on your StartIndex and PrimitiveCount parameters to DrawIndexedPrimitive().   ;  thanks for the reply.I thought the same in the beginning, but why the problem does not happen when I render only the scene without cube map? (or the cube map without scene?);Quote:Original post by fratthanks for the reply.I thought the same in the beginning, but why the problem does not happen when I render only the scene without cube map? (or the cube map without scene?)Because your code either changes the size of the index buffer or the parameters to DrawIndexedPrimitive when you render the cube map.   ;  I still don't get it :(I draw usingif FAILED(manager.GetDevice()->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, params.nVertices, 0, nbPrimitives))hr = E_FAIL;where params is a data structure holding the number of vertices.Since StartIndex is 0, the only possibly wrong parameter is PrimitiveCount, right?I am drawing with D3DPT_TRIANGLELIST, so PrimitiveCount * 3 must be equal to the number of indices currently loaded in the index buffer, if I am not wrong.To be proof error, just before drawing I doLPDIRECT3DINDEXBUFFER9 pCurrIB = NULL;if FAILED(manager.GetDevice()->GetIndices(&pCurrIB))assert(false);D3DINDEXBUFFER_DESC desc_curr_ib;if FAILED(pIB->GetDesc(&desc_curr_ib))assert(false);int nbPrimitives = (desc_curr_ib.Size / 2) / 3;desc_curr_ib.Size holds the size (in bytes) of the current index buffer. If I divide it by 2, I obtain the number of indices (each index gets 2 bytes), then I divide By 3 and obtain the number of primitives.At this point I use the DrawIndexedPrimitive and it still fails, but why?;  Bump?   ;  1. Is desc_curr_ib.Format definitely D3DFMT_INDEX16 and not D3DFMT_INDEX32?2. What does your SetStreamSource() call look like? Specifically, is the OffsetInBytes parameter 0?   ;Quote:1. Is desc_curr_ib.Format definitely D3DFMT_INDEX16 and not D3DFMT_INDEX32?It is D3DFMT_INDEX16.Quote:2. What does your SetStreamSource() call look like? Specifically, is the OffsetInBytes parameter 0?It is like this:if FAILED( pD3DDevice->SetStreamSource( 0, m_pD3DVB, 0, sizeof(VERTEX)))return E_FAIL;So, yes, OffsetInBytes is 0. I do SetStreamSource each time before rendering with DrawIndexedPrimitive.The problem could be caused by something related to the fact that I am rendering on two different render targets (the cubemap and the backbuffer), but I still can not figure out what.;  If you're absolutely sure that the parameters to DrawIndexedPrimitive() are correct (I'd put a breakpoint on each one and step over the call to find out which one is giving the error in the debug spew, and then check the parameters passed to the function), are you able to create a minimalist program that shows the bug and upload it (To rapidshare or some other file sharing site) for us to check?   