PDA

View Full Version : Catching glerrors when they occur



FXO
05-28-2002, 06:15 AM
Hey there!

Is there anyway of making the program break when a glError occurs?

When I'm looking for causes for glErrors now Im cluttering the code with "if (glError())" statements.
Needless to say this is very time-consuming, and not that exciting...

Thanks
/Fredrik Olsson

Azdo
05-28-2002, 07:57 AM
Originally posted by FXO:
Im cluttering the code with "if (glError())" statements.
Needless to say this is very time-consuming, and not that exciting...


I think this is the way, but note that not every GL command is likely to produce such errors. You could test only when setting the pixelformat and textures. I don't think you ever get an error while drawing. As setting video mode and textures doesn't happen every frame, you don't get any penalty perfomance.

Other errors, like a glBegin() without a glEnd() aren't needed to be checked in the release code, once you have made sure that they are all in pairs.

Leyder Dylan
05-28-2002, 09:43 AM
For my engine, I use this :

Ex :

if (!Init_MultiTexture))
{
Add_Log("MultiTexturing Error");
return false;
}
else Add_Log("MultiTexturing OK");

Leyder Dylan
05-28-2002, 09:46 AM
For my engine, I use this :

Ex :

if (!Init_MultiTexture))
{
Add_Log("MultiTexturing Error");
return false;
}
else Add_Log("MultiTexturing OK");

FXO
05-28-2002, 10:51 AM
There are lots of errors that can occur at anytime during rendering.
e.g. Stack over/underflow, invalid enums, etc.

Im not worried about performance, Im just looking for a way to see exactly what command caused the error.

FXO
05-28-2002, 10:57 AM
Leyder Dylan, I use similar error checking for extensions and other things.

But I there are so many unpredictable places an glError() could occur in my program.

Syslock
05-28-2002, 02:23 PM
I only use a single call to glGetError(); at the end of my scene
rendering.

If it catches an error, then I trace the error back. But, I often
don't get any errors, so I only use it as a sanity check every once
in a while.

Azdo
05-29-2002, 08:06 AM
Originally posted by FXO:
There are lots of errors that can occur at anytime during rendering.
e.g. Stack over/underflow, invalid enums, etc.

Im not worried about performance,

But that errors can be fixed at compile time, you can get the sizes of the stacks by using glGet(), so you never overflow them. If you pass a invalid enum, this is a typo, once you detect it, you have not to check for errors on that part of the code.

BTW, yes, you talked about performance in your first post. You said glError() was "time-consuming".

mikael_aronsson
05-29-2002, 12:08 PM
Hi !

Put a glGetError() at the end of the rendering code, if you do get an error there you can track it down by adding checks if you need to, if you would be lucky enough to be running Mesa yoy could set the MESA_DEBUG environment variable that prints error messages to the console.

Mikael

henryj
05-29-2002, 12:20 PM
Here's what I use...

#define GL_ASSERT() {GLenum sci_err; while ((sci_err = glGetError()) != GL_NO_ERROR) \
cerr << "OpenGL error: " << (char *)gluErrorString(sci_err) << " at " << __FILE__ <<":" << __LINE__ << endl;}

careful of the formatting.

This wont tell you which gl* command caused the error but will tell where you caught the error, which is handy if you have 2k glGetError()s sprinkled through your code. Plus it's less to type.

FXO
05-29-2002, 06:59 PM
hejryj, exactly what I was looking for thanks!

Azdo, I meant that finding where in
the code the glError() occured was time-consuming, not the function itself.
>Im cluttering the code with "if (glError())" statements.
>Needless to say this is very time-consuming, and not that exciting...

mikael aronsson, thats the same way I seek for error sources, not very efficient http://www.opengl.org/discussion_boards/ubb/frown.gif


Thank you all for your replies!
/Fredrik Olsson

mikael_aronsson
05-29-2002, 10:22 PM
Hi !

Just one thing, be careful not to put the GL_ASSERT line between glBegin() glEnd(), if I remeber correct you can't even call glGetError() inside a glBegin/End block.

Mikael

FXO
05-30-2002, 06:24 PM
Ok, thanks! http://www.opengl.org/discussion_boards/ubb/smile.gif