OpenGL Window ID's

A co-worker and I are developing an OpenGL 2D Plotting class using the Qt GUI library. The application that we are using the plots in switch between displaying a couple plots to multiple plots at one time, each time destroying and creating a new openGL plot each time. This is creating a new problem, after a while of destroying and redrawing the plots we get the error:

 
X Error: GLXBadContext 146
   Major opcode: 154
   Minor opcode: 3
   Resource ID: 0x7000484
QGLContex: makeCurrent( ): Failed

This is on a Solaris machine. My co-worker believes that we are running out of window ID’s for the system. How do you completely “delete” an OpenGL context and free the window ID’s. Or are we completely wrong is with the window id’s running out?

Thanks

Well you seem to be using a wrapper called QGLContext.

makeCurrent failed but creation probably failed before this.

Make sure you’re deleting the QGLContext. I did a quick check and it doesn’t look like it has an ability to destroy it’s context explicitly, so don’t keep calling the create method in a single QGLContext. Delete it and use a new QGLContext.

I haven’t checked the internals to see if the delete will destroy the context it should.

Alternatively use one QGLContext and only call create once on initialization, that wold be my strong recommendation unless you’re opening & closing a rendering window and want to free resources.

Your problem is similar to one I encountered earlier. It sounds like you are not properly deleting your QGLWidgets. Qt appears to wait until the end to delete all its QGLWidgets so if you are just discarding them without actually calling delete you will run out of contexts because all the widgets will still exist even though your program thinks they are all gone. I traced this problem by setting a break point in my subclassed QGLWidget’s destructor and it wasn’t entering it until termination of the program at which time it freed every QGLWidget I created. Hopefully this will help you.