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
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