Login  Register

Re: Error Making Context Current JOGL 2.0 rc9

Posted by Moa on Aug 04, 2012; 9:29pm
URL: https://forum.jogamp.org/Error-Making-Context-Current-JOGL-2-0-rc9-tp4025517p4025754.html

I figured out what the problem was in my case.

Using JoGL from early 2012 I found I needed to render by doing something like this:

public void display(GLAutoDrawable drawable) {
    try {
      if (!drawable.getContext().isCurrent()) {
        drawable.getContext().makeCurrent();
      }
      // Do the rendering ...
    } finally {
        drawable.getContext().release();
    }
}

By the time I got around to upgrading to JoGL 2.0 rc9 I found that this code was raising a "Context not current" exception. That's when I found this thread. Now I have worked through the issue and believe I have an explanation and fix (for my code at least).

The problem here is the call to release the context. If I remove that then I can render without this "Context not current" exception successfully on Windows, Linux and Mac OS X (10.8, although GLCanvas doesn't work here due to broken Mac pbuffer support, but GLJPanel works nicely).

It appears that the paintComponent() method of JoGL don't ensure that the context is current before drawing, so if you release the context it doesn't get re-bound and the exception is raised. If any of the JoGL maintainers are reading this thread then perhaps you could consider overriding paintComponent() to acquire the GL context if doesn't have it already, that way things would be a lot more robust (IMHO) no matter what a JoGL client developer did.

To make things crystal clear, doing rendering using the following code works for me using JoGL 2.0 rc9 (and pre-rc10):

public void display(GLAutoDrawable drawable) {
    try {
      if (!drawable.getContext().isCurrent()) {
        drawable.getContext().makeCurrent();
      }
      // Do the rendering ...
    } catch (Throwable th) {
      // Log and supress/ignore the exception. Do not release the OpenGL context.
    }
}

I hope this helps someone in the future.