GLContext.makeCurrent() problems!

Hello,
I’ve been working on a JOGL application using active rendering. I’ve based a lot of it off of Andrew Davison’s chapter on JOGL (http://www.java-gaming.org/forums/index.php?topic=12512.0). He extends an AWT Canvas to create the class that has the thread that does all the GL rendering, but wraps it in a JPanel. I tried to create one class, extending JPanel, to handle the GL rendering thread. I created a Canvas as an instance variable in that classand added it to the panel. Then I add my custom, threaded panel to a JFrame. But whenever I try to make the context current to make GL calls, a GLExeption is thrown:

Exception in thread "Thread-2" javax.media.opengl.GLException: Unable to lock surface
        at com.sun.opengl.impl.windows.WindowsOnscreenGLDrawable.lockSurface(WindowsOnscreenGLDrawable.java:169)
        at com.sun.opengl.impl.windows.WindowsOnscreenGLContext.makeCurrentImpl(WindowsOnscreenGLContext.java:57)
        at com.sun.opengl.impl.GLContextImpl.makeCurrent(GLContextImpl.java:118)
        at quantum.graphics.RenderJPanel.makeContextCurrent(RenderJPanel.java:108)
        at quantum.graphics.RenderJPanel.run(RenderJPanel.java:123)
        at java.lang.Thread.run(Thread.java:595)

(I called my JPanel RenderJPanel).
Some of my code:


  private void makeContextCurrent()
  {
    try
    {
      while(context.makeCurrent()==GLContext.CONTEXT_NOT_CURRENT)  // <---- GLException happens here
        Thread.sleep(50);
    }
    catch(InterruptedException e){e.printStackTrace();}
  }

  public void run()
  {
    try
    {
      while((!ready)||(!isVisible()))
        Thread.sleep(50);
    }
    catch(InterruptedException e){e.printStackTrace();}

    makeContextCurrent();  //  <---- GLException happens in this call

    gl=context.getGL();
    glu=new GLU();

    //rendering=new Rendering(this,gl,glu);

    if(renderer!=null)
    {
      init(); // do gl initialization stuff
      context.release();

      while(running)
      {
        makeContextCurrent();

        render(); // draw stuff
        drawable.swapBuffers();

        context.release();
      }

      shutdown(); // clean up gl stuff
    }

    context.destroy();
    System.exit(0);
  }

I’m not creating any other threads in the program, o I don’t see how the context could already be current on a different thread. The javadoc says the exception can also be thrown due to “non-recoverable, window system-specific errors.” That doesn’t help me much though.

Is there a problem with combining the JPanel and the Canvas in the same class? Anything else I’m doing wrong? If more code would be helpful, I can post it too.
Thanks for the help in advance.

Is there a concrete reason why you aren’t using the GLEventListener mechanism? If you have confusion about how to use the GLContext class I would strongly recommend you use the framework already in place.

If you absolutely need to manipulate GLContexts manually, please post complete code so we can diagnose what is going wrong.