Vanilla Vertex Arrays Crash For No Reason.

Started by
17 comments, last by silvermace 19 years, 5 months ago
Hi all, FYI, im running XPSP2, VC2003.NET, Radeon 9500 Pro, Cat 4.9. and im using C++ and nVidia's Cg 1.2 so here's the problem: when i load my terrain data as triangles it crashes when i render. the error is to the tune of "Access Violation 0x0000005 when attempting to read location 0x00000000" now the obvious thing there is to check that i'm not passing in any null pointers, i did. i disabled everything but vertex arrays and rendered, still got the problem. next thing i checked was that verticies and tc's etc were valid, they were. then i checked that all my indices were in range... and they are. odd stuff: there are around 7900 polygons, so ~23000 verts.. but when i render LESS than 5913 verticies ie. glDrawElements( GL_TRIANGLES, 5912, ... ) it renders without crashing. i check the index values for indicies past 5912, they are all valid. if you need code, i can supply, i can't really describe the problem any more than that until anyone wants some specifics. Thanks in Advance, Danu
"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website
Advertisement
To make things interesting....
if i break the glDrawElements call into a loop
ie. instead of
glDrawElements( GL_TRIANGLES, mesh.polyCount * 3, GL_UNSIGNED_INT, &mesh.polys[0] );
i do this:
for(int i=0; i<mesh.polyCount; i++)  glDrawElements( GL_TRIANGLES, 3, GL_UNSIGNED_INT, &mesh.polys);
it works.

WTF.
"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website
Whats mesh.polys?
-- I waz here --
struct Polygon {
uint a, b, c;
};

vector<Polygon> polys;
"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website
It's not a vanilla vertex array if you're using a vector to store the data. I'm kinda wondering WHY you're doing that in the first place...

Try putting it all into a simple array:

eg:
Polygon *polys;

and somewhere in your init routines:
polys = new Polygon[polyCount];

And then just calling:
glDrawElements(GL_TRIANGLES, mesh.polyCount * 3, GL_UNSIGNED_INT, mesh.polys);

Betcha it'll work.
-----BEGIN GEEK CODE BLOCK-----Version: 3.12GCS/M/S d->+(++) s+: a19? C++++ UL++ P+++ L+ !E W+++ N+ o++ K? w!O M-- V? !PS PE Y+ PGP t++ 5+++ X R tv+> b+(++)>+++ DI+++>+++++ D++G e>++++ h! r y?------END GEEK CODE BLOCK------
Quote:Original post by overflowed_
It's not a vanilla vertex array if you're using a vector to store the data. I'm kinda wondering WHY you're doing that in the first place...

Try putting it all into a simple array:

eg:
Polygon *polys;

and somewhere in your init routines:
polys = new Polygon[polyCount];

And then just calling:
glDrawElements(GL_TRIANGLES, mesh.polyCount * 3, GL_UNSIGNED_INT, mesh.polys);

Betcha it'll work.
Vector is guaranteed by the standard to provide contiguous memory, betcha it won't make a difference.

PS. i will try it any way!
"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website
did element-by-element copy into a plane jane array, still crashed in the same place. here's the exact message
Unhandled exception at 0x692ae676 in Ignite.exe: 0xC0000005: Access violation reading location 0x00000000.
looks like a good 'ol NULL pointer exception, but i dunno where.. as i said all the data looks valid.
/continues to search..
"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website
Try setting up some breakpoints ahead of the code you think is causing the problem, then put some watches on any possible pointers near the problem section.

Also, if you can post the entire vertex array section (everything for this particular render), there might be something as simple as a typo causing a problem.
-----BEGIN GEEK CODE BLOCK-----Version: 3.12GCS/M/S d->+(++) s+: a19? C++++ UL++ P+++ L+ !E W+++ N+ o++ K? w!O M-- V? !PS PE Y+ PGP t++ 5+++ X R tv+> b+(++)>+++ DI+++>+++++ D++G e>++++ h! r y?------END GEEK CODE BLOCK------
try this

glDisableClientState( GL_VERTEX_ARRAY );
glDisableClientState( GL_NORMAL_ARRAY );
glDisableClientState( GL_COLOR_ARRAY );
glClientActiveTexture( GL_TEXTURE0 );
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
glClientActiveTexture( GL_TEXTURE1 );
glDisableClientState( GL_TEXTURE_COORD_ARRAY );

and then draw it
u wont see anythihng but hopefully it wont crash, then comment out
glDisableClientState( GL_VERTEX_ARRAY ); + run it again etc
Quote:Original post by overflowed_
Try setting up some breakpoints ahead of the code you think is causing the problem, then put some watches on any possible pointers near the problem section.

Also, if you can post the entire vertex array section (everything for this particular render), there might be something as simple as a typo causing a problem.
its crashing INSIDE the OpenGL driver, not in my code. ie. exception comes from
atioglxx.dll!692ae676()


i disabled everything but vertex arrays, still crashes, but when i disable everything, its fine. (nothing on the screen though :p)

my renderer flush function if anyone cares:
void RRenderer::flush() {		CVector3 *ve = 0;	int r = 0;	int i = 0;	int normArrayActive = 0;	// reset client states	for(int i=0; i<8; i++)	{		glClientActiveTextureARB(GL_TEXTURE0_ARB+i);		glActiveTexture( GL_TEXTURE0_ARB+i);		glDisable( GL_TEXTURE_2D );		glDisableClientState( GL_TEXTURE_COORD_ARRAY );	}	glEnableClientState( GL_TEXTURE_COORD_ARRAY );	glEnableClientState( GL_VERTEX_ARRAY );	glEnableClientState( GL_NORMAL_ARRAY );	glEnableClientState( GL_COLOR_ARRAY );	glCullFace( GL_FRONT );	glEnable( GL_CULL_FACE );	glMatrixMode( GL_MODELVIEW );	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );			RCgInfo& cgc = CgContext;		//iterate through rendering objects		for( uint o=0; o<objects.size(); o++ )		{			RObject *co = &objects[o];			//iterate through meshes of current object			for( uint m=0; m<co->meshes.size(); m++ )			{				RMesh *cm = &co->meshes[m];				RPolygon* p = cm->polybuffer.get(0); //returns polybuffer.polys[0]				RVertexBuffer& vb = cm->vertbuffer;				RShader *sh = getShader( cm->shader );								if( sh == NULL && (Renderer.settings & GENERATION_GL15) ) //some kind of error					continue;				glPushMatrix();					if( cm->transfomMat != NULL )						glMultMatrixf( cm->transfomMat->entries ); 					if( sh != NULL )					{						//bind the decal texture						glClientActiveTextureARB(GL_TEXTURE0_ARB);						glActiveTexture( GL_TEXTURE0_ARB);									// bind the texture coordinates						glEnableClientState( GL_TEXTURE_COORD_ARRAY );						glTexCoordPointer( 2, GL_FLOAT, 0, (GLvoid*) vb.getTc( RVertexBuffer::TEXCOORD0, 0) );					}					if( Renderer.settings & GENERATION_GL15 )						bindShader(cm->shader);					if( vb.get(RVertexBuffer::NORMAL, 0) ) {						glEnableClientState( GL_NORMAL_ARRAY );						normArrayActive = 1;						glNormalPointer( GL_FLOAT, 0, (GLvoid*) vb.get(RVertexBuffer::NORMAL, 0) );					}					if( vb.get(RVertexBuffer::TANGENT, 0) && dx9 ) { //send the tangent data through the color arrays						glColorPointer( 3, GL_FLOAT, 0, (GLvoid*) vb.get(RVertexBuffer::TANGENT, 0) );					} else {						glDisableClientState( GL_COLOR_ARRAY );					}						glPushAttrib( GL_LIGHTING_BIT );							if( cm->flags & RMesh::MESH_NOLIGHT ) {								glDisable( GL_LIGHTING ); 							}							int numElems = cm->polybuffer.polycount * 3;													CVector3 *pVerts = vb.get(RVertexBuffer::VERTEX, 0);							glVertexPointer( 3, GL_FLOAT, 0, (GLvoid*) pVerts );							glDrawElements( GL_TRIANGLES, numElems, GL_UNSIGNED_INT, (GLvoid*) p); // crashes here for no reason.						glPopAttrib();				glPopMatrix();				unbindShader(cm->shader);			}		}			glDepthFunc( GL_LEQUAL );}
"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website

This topic is closed to new replies.

Advertisement