Now this is just weird

First, my system:
Dual 700 PIII
1024 MBs of ram
nVidia GeForce 2 GTS(Elsa Gladiac)
Detonator 29.42 drivers
(23.11 Stereo driver w/ Elsa Revelator glasses)

OK, strange bug…

I am rendering my scenegraph in a series of glDrawElements calls, and then rendering some text using:

glBegin(GL_QUADS);
glTexCoord2f(…);
glVertex3f(…);
glTexCoord2f(…);
glVertex3f(…);
glTexCoord2f(…);
glVertex3f(…);
glEnd();

So far so good, right?

Except, my app locks up when stereo mode is turned on.(Num-lock don’t work, mouse is dead, music stops playing, etc…)

So, I started turn off components and trying to figure out what is causing it to freeze. Well, eventually, it turns out that when I comment out the text rendering, it works fine in stereo. OK, so I decide to use glGetError and log all the errors. I make the following macro:

#define RunGL(x) {
x;
GLenum gle;
gle=glGetError();
if(gle!=GL_NO_ERROR)
Log.Post("OpenGL error "%s" on line %i
",gluErrorString(gle),LINE);
}

And replace all GL commands with:

RunGL(glCommand2f(stuff))

Then, I run my app normally(stereo mode off), and check my log.

To my horror, I find that the glEnd() command in the text rendering code is giving an “Invalid Operation” error every time it is called. So I figure I’m calling the glBegin, glEnd combo above in between some other glBegin/glEnd block. So, I replace the above code with this:

glEnd(); //added this
glBegin(GL_QUADS);
glTexCoord2f(…);
glVertex3f(…);
glTexCoord2f(…);
glVertex3f(…);
glTexCoord2f(…);
glVertex3f(…);
glEnd();

This should handle times where I’m accidentally calling this during a rendering operation. I run it, but instead of getting the expected invalid operation JUST on the first glEnd() and not on the last one, I get it on both of them!

I’ve been trying to track this down for a while, so any help is much appreciated.

Thanks,
-Shard

[This message has been edited by Shard (edited 07-09-2002).]

There are four vertices in a quad.

Yeah, I know, but that’s not the problem. I just provided an example. Besides, even if I didn’t have four verts, it still shouldn’t give me an invalid operation error.

-Shard

When you turn stereo on do you get a valid opengl context?

sigh

I will re-iterate that when I turn off my text rendering (the glBegin() glEnd() thing) everything works fine both windowed mode, fullscreen mode, AND stereo mode.

-Shard

Maybe I should state this another way…

What would cause glEnd() to return an “Invalid Operation”?

The only time it should is when there is no glBegin() statement before it, right?

But my code has this, and it still gives the error!

-Shard

Originally posted by Shard:
What would cause glEnd() to return an “Invalid Operation”?
The only time it should is when there is no glBegin() statement before it, right?

sigh

The irony of it all. The thing causing your GL_INVALID_OPERATION is your call to glGetError().

“GL_INVALID_OPERATION is generated if a command other than glVertex, glColor, glIndex, glNormal, glTexCoord, glEvalCoord, glEvalPoint, glMaterial, glEdgeFlag, glCallList, or glCallLists is executed between glBegin and the corresponding glEnd.”

Im not saying that solves your original problem, but thats where the GL_INVALID_OPERATION is coming from.

It can’t complete the quad - what else do you want the glerror to say? GL_CANT_COMPLETE_QUAD ?!

Nope, that wasn’t it. First off, I AM providing 4 verts. Second, it’s irrelevant! The Red Book says that if there aren’t enough verts to complete a primitive, they will be ignored! No error here!

Second, my call to glGetError is NOT causing the error. I removed it and nothing changed.(The error was still logged)

What’s more, even if I remove all vertex/texcoord definitions between glBegin and glEnd, like this:

glBegin(GL_QUADS);
//glTexCoord2f();
//glVertex3f();
//glTexCoord2f();
//glVertex3f();
//glTexCoord2f();
//glVertex3f();
//glTexCoord2f();
//glVertex3f();
glEnd();
glGetError()<-Still returns GL_INVALID_OPERATION

-Shard

[This message has been edited by Shard (edited 07-10-2002).]

I don’t think the driver implementation of shutter glass stereo is very solid.
http://www.opengl.org/discussion_boards/ubb/Forum3/HTML/004392.html

Originally posted by Shard:
Second, my call to glGetError is NOT causing the error. I removed it and nothing changed.

Like I said, it may not have caused your original error, but it does most definitely cause a GL_INVALID_OPERATION of its own. I even tried it with a skeleton app before I posted just to confirm. Try calling glGetError immediately before your glBegin and make sure it returns GL_NO_ERROR. Then make sure you do not call it again until after glEnd. This means, make sure you dont call it directly, or call any functions that call it. Be absolutely positive about that. Then, call glGetError AFTER glEnd, and see if it still gives you a GL_INVALID_OPERATION.

Assuming it still does, I’m not sure what else is wrong. Are you postive you arent doing anything but calling glVertex, glColor, glTexCoord*, etc? By any chance, do you have any vertex arrays enabled while doing this? I imagine that could cause a problem, although I’m not sure how the spec says the implementation should behave if it happened.

Thanks for the help, it worked!

I turned off all arrays, called glGetError() right before glBegin(), and removed all glGetError()s inside the Begin/End Block.

The error WAS actually occuring before the glBegin statement, but because I was calling glGetError() afterwards, it reported the invalid operation at glEnd() instead of at the proper place. It turned out the invalid operation was coming from a completely different Begin/End block which I had forgotten to comment out when I stripped down my renderer. Anyway, it works perfectly now, so thanks for all the help.

Somebody please put this in the FAQ:
NEVER CALL glGetError() INSIDE OF A glBegin/glEnd BLOCK!!!

-Shard

Originally posted by Shard:
Somebody please put this in the FAQ:
NEVER CALL glGetError() INSIDE OF A glBegin/glEnd BLOCK!!!

I remember the first time I did that. I had a perfectly working app and thought “I guess maybe I should add some better error handling”. Imagine my surprise when it suddenly started spewing errors.

Shard, why was the error only occurring when stereo was turned on?

I imagine the stereo rendering path probably isnt as fully tested and debugged as the rest of the driver is.

I tried to do some more tests with stereo turned on, but it’s hard to turn off specific components when they’re heavily linked to my renderer. I’m using lots of OpenGL functions for GUI rendering, such as scissoring, viewports, mixed vertex array and glBegin/glEnd code, and I fool with the projection matrix a lot. I’m guessing the stereo driver wasn’t built to handle that kind of rendering.

BTW, The freeze occurs at the first SwapBuffers after I do all my rendering. Can anybody from nVidia tell us what may be causing this?

-Shard