Jump to content
  • Advertisement
Sign in to follow this  

drawrangeelements creating giving access violation reading 0x0000

This topic is 3680 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

My code is something like:

vector<float> allvertexdata;
vector<int> allindexdata;

//... fill in the two buffers ...

if (allindexdata.size()*4!=totalISize) return false;
if (allvertexdata.size()*4!=totalVSize) return false;

nmesh.dbg_indexdata=allindexdata;
nmesh.dbg_vertexdata=allvertexdata;

glGenBuffersARB(1,&nmesh.VertexBuffer);
glBindBufferARB(GL_ARRAY_BUFFER,nmesh.VertexBuffer);
glBufferDataARB(GL_ARRAY_BUFFER,totalVSize,&allvertexdata[0],GL_STATIC_DRAW_ARB);

glGenBuffersARB(1,&nmesh.IndexBuffer);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,nmesh.IndexBuffer);	
glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB,totalISize,&allindexdata[0],GL_STATIC_DRAW_ARB);	

glBindBufferARB(GL_ARRAY_BUFFER_ARB,0);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,0);	


//... do some other initialization stuff ...


//... start rendering:
const char* ptrbase=0;

glBindBufferARB(GL_ARRAY_BUFFER,m.VertexBuffer);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,m.IndexBuffer);	
		
glDisableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);	
glNormalPointer(m.ptrNormalSize,m.ptrNormalStride,ptrbase+m.ptrNormalOffset);
for (int i=0;i<8;i++) {
	glClientActiveTextureARB(GL_TEXTURE0_ARB+i);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}

glEnableClientState(GL_VERTEX_ARRAY);	
glVertexPointer(m.ptrVertexSize,m.ptrVertexFormat,m.ptrVertexStride,ptrbase+m.ptrVertexOffset);

for (vector<CBatch>::const_iterator bit=m.batches.begin();bit!=m.batches.end();bit++) {

	if (0) {
		glBegin(GL_TRIANGLES);
		char* dbgvbase=(char*)&m.dbg_vertexdata[0];
		for (int i=bit->indexStart;i!=bit->indexEnd;i++) {
			int v=m.dbg_indexdata;		
			glColor4f(1.0f,3.0f,3.0f,1.0f);
			Vector3* dn=(Vector3*)(dbgvbase +  v*m.ptrNormalStride + m.ptrNormalOffset);
			glNormal3f(dn->x,dn->y,dn->z);
			Vector3* dv=(Vector3*)(dbgvbase +  v*m.ptrVertexStride + m.ptrVertexOffset);
			glVertex3f(dv->x,dv->y,dv->z);
		}
		glEnd();
	} else {
		glDrawRangeElements(GL_TRIANGLES,bit->vertexStart,bit->vertexEnd,bit->indexCount,GL_UNSIGNED_INT,ptrbase+bit->indexStart*4);
	}
}

The code works fine when I change the 0 to a 1 and use the glBegin stuff instead of the glDrawRangeElements command. When I used glDrawRangeElements, I get an access violation reading 0x00000000. The last pointer passed into it is null, but shouldn't glDrawRangeElements treat that as an index into the element buffer? Basically, I expect glDrawRangeElements to work exactly the way the code above it does (just more efficiently), but for some reason it doesn't work the way I think it should. Also vertexStart and vertexEnd should to the minimum and maximum index referred to by any of the indices right? (or is vertexStart something that is added to all of the indices?) Any ideas?

Share this post


Link to post
Share on other sites
Advertisement
Thanks, that was it.

I accidently removed the GLenum type parameter instead of the GLint size one... man that would have taken me hours to notice.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!