DrawIndexedPrimitive fails with Access violation

Started by
3 comments, last by dpro 17 years, 10 months ago
Ok I removed this question and decided to ask a new one, relating to the same thing. I keep on getting a Access Violation whenever I try to use drawindexedprimitive...

p_dev->SetIndices( idxBuff );
hr = p_dev->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, totalVerts, 0, numPolys );



int m_cols = 20;
int m_rows = 20;
polySize = m_cols * m_rows * 2;
numInd = polySize * 3;
numPolys = m_cols * m_rows * 2;
totalVerts = (m_cols+1) * (m_rows+1);
vertices = new vtx[ totalVerts ];


I created a vertex buffer of totalVerts * sizeof( vtx ) size, as is usual. vtx is a struct with a D3DXVECTOR3 position vector and a color value. I created an indexbuffer with a size of numInd size, which in this case is 2400 indices total. 20 * 20 * 3(vertices per triangle) * 2(triangles per "square") But I must be setting something wrong because of the access violation, but I can't seem to see what. [Edited by - dpro on May 22, 2006 5:00:53 PM]
Advertisement
I can't find anything out of place in the code you posted. Could you post some more code? Show your full vertex/index buffer setup and your full draw code and we'll see if there's anything wrong with it.
Hack my projects! Oh Yeah! Use an SVN client to check them out.BlockStacker
Can't find anything wrong either.
Two shots in the dark:
- mix up of 16/32 bits in the index buffer setup?
- missing SetStreamSource, SetIndices or SetFVF calls in the rendering procedure?
Do you have the debug runtimes installed with the output set to maximum? Any warnings or errors there?

I seem to remember having this problem when I was using software vertex processing, if you try to access a vertex using an invalid index (E.g. if any indices have an index >= totalverts).
Thanks for the replies, I found out that I had been silly and filled my indexbuffer improperly, meaning I was heading off the end of the vertexbuffer array. Which as we all know is a no-no :) Thanks again!

This topic is closed to new replies.

Advertisement