PDA

View Full Version : Please help me track down a mysterious gl error


TomorrowPlusX
2006.08.03, 02:27 PM
Long ago I found a macro ( I think posted by arrekusu ) called glError, which will look for gl error state and display it to stdout.


#define glError() { \
GLenum err = glGetError(); \
while (err != GL_NO_ERROR) { \
printf("glError: %s caught at %s:%u\n", (char *)gluErrorString(err), __FILE__, __LINE__); \
err = glGetError(); \
} \
}


Ever since, I've used it very liberally in my code to help me keep gl happy. That and running my apps under gl profiler with "Break on GL Error" checked.

Now, I've come across a gl error which I simply don't understand. I can't figure out what's causing it, or why. Basically, I'm getting the error immediately after calling glEnd(), after drawing a bunch of quads. The error doesn't occur *before* calling glEnd, but occurs right after.

Here's a condensation of my offending code:

float texScale = water()->normalmapScale();
PatchVec::const_iterator it( _patches.begin() ), end( _patches.end() );

glError(); // no error here
glBegin( GL_QUADS );

for ( ; it != end; ++it )
{
const patch &p = *it;

glMultiTexCoord2f( GL_TEXTURE0, 0.0f, 0.0f);
glNormal3f( 0.0f, 0.0f, 1.0f );
glVertex3f( p.vertices[0].x, p.vertices[0].y, 0.0f );

glMultiTexCoord2f( GL_TEXTURE0, texScale, 0.0f);
glNormal3f( 0.0f, 0.0f, 1.0f );
glVertex3f( p.vertices[1].x, p.vertices[1].y, 0.0f );

glMultiTexCoord2f( GL_TEXTURE0, texScale, texScale );
glNormal3f( 0.0f, 0.0f, 1.0f );
glVertex3f( p.vertices[2].x, p.vertices[2].y, 0.0f );

glMultiTexCoord2f( GL_TEXTURE0, 0.0f, texScale );
glNormal3f( 0.0f, 0.0f, 1.0f );
glVertex3f( p.vertices[3].x, p.vertices[3].y, 0.0f );

glError(); // no error here
}

glError(); // no error here
glEnd();
glError(); // error shows up here



The error reported is "invalid operation".

I've trimmed and stripped the code clean and I still get the error. I can't figure out what the error is, or what's causing it.

Help! Please!
:blink:

akb825
2006.08.03, 02:34 PM
ERRORS
GL_INVALID_OPERATION is generated if glGetError is executed between the
execution of glBegin and the corresponding execution of glEnd. In this
case glGetError returns 0.
I'd say that's you're error. ;) Generally, you can't do anything but vertex operations between glBegin and glEnd functions.

TomorrowPlusX
2006.08.03, 02:48 PM
Well, that wasn't it. I took out the calls in between begin/end, but it's still happening after glEnd.

Woulda been nice, if it had been :p

EDIT: I got it! I was doing something "clever" with display lists in between glBegin and glEnd -- that was the problem. By clever, I mean "misunderstanding of opengl". I solved it, though, and it's working.

Thanks!

akb825
2006.08.03, 03:04 PM
I only wish all errors were caused by being "clever". I had an Invalid Value error on my MacBook Pro with using gluPerspective, and the visual symptoms ranged from showing nothing at all to really really wacked out drawing order problems. It worked fine on my PowerMac, however, and with an identical call on another view on my MBP. I finally decided to plug in the exact formula that gluPerspective uses to manually call glFrustum, and guess what: problem solved.

arekkusu
2006.08.03, 05:32 PM
Note is also an error to call glGetError between Begin and End. ;)

Also, a good modification to that macro is:

#if DEBUG
#define glError() (...current definition...)
#else
#define glError()
#endif

So that in the release build of your application, the define noops, and you aren't calling glGetError.

I strongly reccomend everyone to call glGetError at least once in your drawing loop during development but in a release build you should not be calling it (you found all the bugs during development, right?)

glGetError is a state query, which you should avoid for reasons which will be made clear at WWDC.

OneSadCookie
2006.08.03, 06:49 PM
Note is also an error to call glGetError between Begin and End. ;)

Also, a good modification to that macro is:

#if DEBUG
#define glError() (...current definition...)
#else
#define glError()
#endif

So that in the release build of your application, the define noops, and you aren't calling glGetError.

How about NDEBUG instead? You *are* using assert(), right?

glGetError is a state query, which you should avoid for reasons which will be made clear at WWDC.

... for those of us lucky enough to attend :( ... I hope Apple will be providing such useful-sounding information to those of us who can't afford $4500 to be there!

Fenris
2006.08.03, 07:49 PM
glGetError is a state query, which you should avoid for reasons which will be made clear at WWDC.
That was just cruel. :P

TomorrowPlusX
2006.08.04, 12:54 PM
Note is also an error to call glGetError between Begin and End. ;)

Also, a good modification to that macro is:

#if DEBUG
#define glError() (...current definition...)
#else
#define glError()
#endif

So that in the release build of your application, the define noops, and you aren't calling glGetError.


Heh. I'm already doing that, I just didn't want to bloat my listing...

Regarding WWDC... well, someday maybe I'll get lucky and get a job doing Mac development ( this is me with my fingers crossed ). Right now I'm employed as a graphic designer, so I can hardly ask my boss to pay for the trip.