Sign in to follow this  
subi

Invalid index data pointer

Recommended Posts

Hi Everyone i am trying to render a pretty basic static mesh that has no y value in D3D9. (it will actually be a bruteforce terrain method but just for testing i dropped the y value for simplicity) here is some code init function:

struct Vertex3f
{
float x,y,z;
};
	Vertex3f *vertices;
	short *indices;

vertexcount = m_iSize * m_iSize *3;
	vertices = new Vertex3f[vertexcount];
	indicecount = (m_iSize-1)*(m_iSize-1)*6;
	indices = new short[indicecount];

    
	//Build our vertex array
		for(int z=0; z<m_iSize; z++ )
					{
						for( int x=0; x<m_iSize; x++ )
						{
						vertices[z*m_iSize+x].x = x*m_fStep;
						vertices[z*m_iSize+x].y = 0;
						vertices[z*m_iSize+x].z = z*m_fStep;
						}
						
					}
	//Build our indice array
		int i=0;
		for(int z=0; z<m_iSize-1; z++ )
					{
						for( int x=0; x<m_iSize-1; x++ )
						{
							//triangle 1
							indices[i] = x +(m_iSize *z);
							i++;
							indices[i] = x + (m_iSize * (z+1));
							i++;
							indices[i] = (x+1) + (m_iSize * (z+1));
							i++;
							//triangle 2
							indices[i] = (x+1) + (m_iSize * (z+1));
							i++;
							indices[i] = (x+1) + (m_iSize * z);
							i++;
							indices[i] = x +(m_iSize *z);
							i++;
							primitivecount+=2;

						}
					}


render function:
m_d3D9dev->SetFVF(D3DFVF_XYZ);
m_d3D9dev->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST,0,vertexcount,primitivecount,indices,D3DFMT_INDEX16,vertices,sizeof(Vertex3f));


running this in debug mode gives me this error First-chance exception at 0x7c80c851 in testdx.exe: 0xC0000005: Access violation reading location 0x00bf1000. Direct3D9: (ERROR) :Invalid index data pointer any ideas what i am doing wrong?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this