Error freeing OpenGL Context

I’m getting the a GLException:

Exception in thread "AWT-EventQueue-0" net.java.games.jogl.GLException: Error fr
eeing OpenGL context
        at net.java.games.jogl.impl.windows.WindowsGLContext.free(WindowsGLConte
xt.java:151)
        at net.java.games.jogl.impl.windows.WindowsOnscreenGLContext.free(Window
sOnscreenGLContext.java:132)
        at net.java.games.jogl.impl.GLContext.invokeGL(GLContext.java:203)
        at net.java.games.jogl.GLCanvas.displayImpl(GLCanvas.java:182)
        at net.java.games.jogl.GLCanvas.display(GLCanvas.java:82)
        at net.java.games.jogl.GLCanvas.paint(GLCanvas.java:89)
        at sun.awt.RepaintArea.paintComponent(Unknown Source)
        at sun.awt.RepaintArea.paint(Unknown Source)
        at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)


I used TraceGL, and these are the methods being called:


glViewport(0,0,492,466)
glViewport(0,0,492,466)
glMatrixMode(5889)
glLoadIdentity()
glMatrixMode(5888)
glLoadIdentity()
glViewport(0,0,492,466)
glViewport(0,0,492,466)
glMatrixMode(5889)
glLoadIdentity()
glMatrixMode(5888)
glLoadIdentity()
glViewport(0,0,492,466)
glViewport(0,0,492,466)
glMatrixMode(5889)
glLoadIdentity()
glMatrixMode(5888)
glLoadIdentity()
glClear(16640)
glLoadIdentity()
glRotatef(360.0,0.0,1.0,0.0)
glBindTexture(3553,1)
glBegin(7)

I am not sure what is going on, but the error happens every time.

I assume you must call glEnd() before you can swap the buffers

public void display(GLDrawable gld) {
        GL gl = gld.getGL();
        
        gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT );
        gl.glLoadIdentity();
        
        float srot = 360 - yrot;
	gl.glRotatef(srot, 0.0f, 1.0f, 0.0f);
        gl.glBindTexture(gl.GL_TEXTURE_2D, textures[0]);
        
        for(int i = 0; i < mp.sq.length; i++) {
            Square sq = mp.sq[i];
            gl.glBegin(GL.GL_QUADS);
                Vertex v = null;
                v = sq.vert[0];
                gl.glTexCoord2f(v.tx, v.ty);
                gl.glVertex3f(v.x, v.y, v.z);
                v = sq.vert[1];
                gl.glTexCoord2f(v.tx, v.ty);
                gl.glVertex3f(v.x, v.y, v.z);
                v = sq.vert[2];
                gl.glTexCoord2f(v.tx, v.ty);
                gl.glVertex3f(v.x, v.y, v.z);
                v = sq.vert[3];
                gl.glTexCoord2f(v.tx, v.ty);
                gl.glVertex3f(v.x, v.y, v.z);
            gl.glEnd();
        }
    }

That’s the code for the part of the section that fails. I do call gl.glEnd().

Is there any part of your program (outside of the display() method you just posted) where you do a context release/destroy? The error in the stack trace seems to think there were problems releasing the OpenGL context.