PDA

View Full Version : wglMakeCurrent



sammie381
10-31-2008, 10:11 PM
Why would calling:
wglMakeCurrent( NULL, NULL );

return GL_INVALID_OPERATION, when the previous GL command returned no error?

And it didn't just return one error, it returned thousands of GL_INVALID_OPERATION error messages.

Is there a limit to how many error codes that glGetError() can store? How would I reset it if I wanted to?

[edit]
I just looked at it again, and it's returning an ENDLESS loop of GL_INVALID_OPERATION error messages.
Why would it do something like this? I thought this removes them:



GLenum error;
while ((error = glGetError()) != GL_NO_ERROR) {
// display error
}

sammie381
11-01-2008, 04:25 AM
Woohoo! I figured it out. You can't call glGetError() when there is no active rendering context,
otherwise you will get stuck in an infinite loop of GL_INVALID_OPERATION errors.

Here's my fix, that's working great now:



if(wglGetCurrentContext() != NULL) {
GLenum error;
while ((error = glGetError()) != GL_NO_ERROR) {
// display error
}
}


I couldn't figure out why my program was crashing all the time!
I know why now!

sammie381
11-01-2008, 01:31 PM
Here's some better code. Probably better to check each time in case some sneaky thread tries to clear
out the active context while I'm digging through GL errors:



if(wglGetCurrentContext() != NULL) {
GLenum error;
while ((error = glGetError()) != GL_NO_ERROR) {
// display error
if(wglGetCurrentContext() != NULL) break;
}
}

MarkS
11-02-2008, 06:21 PM
What is the purpose of the while loop in the first place? Shouldn't is be an "if" statement?

sammie381
11-03-2008, 12:01 AM
What is the purpose of the while loop in the first place? Shouldn't is be an "if" statement?

There may be more than one error returned.

Although it's probably safer to just check for one error and skip the entire while loop all together! It's a bloody trap waiting to happen. It'll crash your app if you're not careful. :)

IMHO, kinda ridiculous if you ask me. Querying for error information *causes* your app to crash.

Anybody know if OpenGL 3.0 does this too?