...jogl.GLException: Unable to lock surface

I made a class which extends a Frame, where I put an instance of the GLCanvas.

When I create an instance of this class from the main function (i.e. from the main thread), there is no problem.

When I create an instance of this class from the event thread (i.e. when the use push a button or something like that), the instruction “canvas.setSize(320, 200);” in the constructor of my class throws an exeption.

When I comment out the “setSize(320, 200);”, there is no problem but my frame is zero sized and the user need to resize it manually :frowning:

The setSize() function cause a reshape() call on the canvas object, which cause this execption to be thrown. Since I don’t call the reshape function myself, the propagation of this exception to the level of the setSize() function is a bug.

Here is the trace of the exception :

net.java.games.jogl.GLException: Unable to lock surface

  at net.java.games.jogl.impl.windows.WindowsOnscreenGLContext.lockSurface(WindowsOnscreenGLContext.java:155)

  at net.java.games.jogl.impl.windows.WindowsOnscreenGLContext.makeCurrent(WindowsOnscreenGLContext.java:107)

  at net.java.games.jogl.impl.GLContext.invokeGL(GLContext.java:162)

  at net.java.games.jogl.GLCanvas.reshape(GLCanvas.java:105)

  at java.awt.Component.setBounds(Component.java:1664)

  at java.awt.Component.resize(Component.java:1601)

  at java.awt.Component.setSize(Component.java:1593)

  at jardin.scene.OpenGLFrame.<init>(OpenGLFrame.java:22)

  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)

  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)

  at java.lang.reflect.Constructor.newInstance(Constructor.java:274)

  at java.lang.Class.newInstance0(Class.java:308)

  at java.lang.Class.newInstance(Class.java:261)

  at jardinier.classBrowserPanel.ClassBrowserPanel.instantiateSelectedTreeNode(ClassBrowserPanel.java:280)

Here is the source of the constructor of my Frame class :

public class OpenGLFrame
extends Frame
{

protected GLCanvas canvas;
protected Scene currentScene = new Scene();

public OpenGLFrame()
{
    GLCapabilities capabilities = new GLCapabilities();
    canvas = GLDrawableFactory.getFactory().createGLCanvas(capabilities);
    canvas.addGLEventListener(currentScene);
    add(canvas);
    canvas.setSize(320, 200);

    pack();
    show();
}


}

Vincent Cantin

I just tried with the nightly build, and the problem is still there.

My guess is that the GL Context hasn’t been set up yet. I believe that JOGL delays the actual creation of the context until first display. So the reshape is happening before the context is created.

Why don’t you try setting the size before adding the GLCanvas?

Could you boil this down into a test case and file an issue on the Issue Tracker page linked off the JOGL web page?

Could you boil this down into a test case and file an issue on the Issue Tracker page linked off the JOGL web page?

Yes, I will do that soon.

I am having a similar problem and was wondering if anyone has come up with a solution to this. I have updated with the nightly build and that didn’t help. The exception only occurs on my windows box. The same application runs fine on the mac. here is part of the exception trace:

net.java.games.jogl.GLException: Unable to lock surface
net.java.games.jogl.GLException: Unable to lock surface
at net.java.games.jogl.impl.windows.WindowsOnscreenGLContext.lockSurface(WindowsOnscreenGLContext.java:155)
at net.java.games.jogl.impl.windows.WindowsOnscreenGLContext.makeCurrent(WindowsOnscreenGLContext.java:107)
at net.java.games.jogl.impl.GLContext.invokeGL(GLContext.java:232)
at net.java.games.jogl.GLCanvas.reshape(GLCanvas.java:97)
at java.awt.Component.setBounds(Component.java:1664)

this comes as the result of a user pressing a button which creates a new instance of a Jwindow extended class which than adds a jogl canvas to its content pane. the excetion occurs at this line:

canvas.setBounds(0,0,width,height);

thanks for any help
-rob

ßI am also currently struggling with an exception of this type. The JOGL User’s Guide indicates that it has to do the with multi-threaded environment of Java interacting with the C-origins of OpenGL:
(the User’s Guide is available at https://jogl.dev.java.net/nonav/source/browse/checkout/jogl/doc/userguide/index.html?rev=HEAD&content-type=text/html). Here’s a relevant quote:

"Both of these models (repaint-on-demand and repaint continually) still require the user to think about which thread keyboard and mouse events are coming in on, and which thread is performing the OpenGL rendering. OpenGL rendering may not occur directly inside the mouse or keyboard handlers, because the OpenGL context for the drawable is not current at this point (hence the warning about storing a GL object in a field, where it can be fetched and accidentally used by another thread). However, a mouse or keyboard listener may invoke GLDrawable.display().

“It is generally recommended that applications perform as little work as possible inside their mouse and keyboard handlers to keep the GUI responsive. However, since OpenGL commands can not be run from directly within the mouse or keyboard event listener, the best practice is to store off state when the listener is entered and retrieve this state during the next call to GLEventListener.display().”

So, the problem referred to in this thread might be avoided by following the advice given here. That is, store off state in the keyboard and mouse listeners, but don’t do anything that will directly cause display of a GLDrawable on the event-handling thread.

Unfortunately, there are still situations where it is hard to avoid having display called from the wrong thread (for example, an IDE that instantiates instances of Java objects: when that Java object contains a GLDrawable, the wrong thread may inadvertantly be called to display it – at least that what seems to be causing the exceptions I’m encountering).

Hope this helps.

Thanks to whoever wrote the User’s Guide. And, if you’re reading this, what about updating it with any new and useful developments in the themes it deals with?

Make sure your window is visible before you call setBounds. The canvas needs to be attached to the screen before you can work with it.

Make sure your window is visible before you call setBounds. The canvas needs to be attached to the screen before you can work with it.

yes, that seems to work, although it is odd that this is not the case when the code is run on the mac.
thanks