net.java.games.jogl.GLException: Surface already u

Hi there…
All I do is to display a JDialog in canvas.repaint() initiated by mouse release. Once out of 20 mouse press I get this error, otherwise every thing is perfect.
It seems again an unsynch thread issue, but this getting out of control in a GUI application that is strongly dependent on mouse events like mine. Setting rendering event to current event is not even an option since more than 5000 objects rendered.
Any body has any idea to get rid of this “Surface already unlocked” error message?
Any hint is deeply appreciated.

Thanks.

Exception occurred during event dispatching:

net.java.games.jogl.GLException: Surface already unlocked

  at net.java.games.jogl.impl.windows.WindowsOnscreenGLContext.unlockSurface(WindowsOnscreenGLContext.java:192)

  at net.java.games.jogl.impl.windows.WindowsOnscreenGLContext.free(WindowsOnscreenGLContext.java:134)

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

  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 net.java.games.jogl.GLCanvas.update(GLCanvas.java:116)

  at sun.awt.RepaintArea.paint(RepaintArea.java:169)

  at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:260)

  at java.awt.Component.dispatchEventImpl(Component.java:3678)

  at java.awt.Component.dispatchEvent(Component.java:3477)

  at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)

  at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)

  at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)

  at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:141)

  at java.awt.Dialog$1.run(Dialog.java:540)

  at java.awt.Dialog.show(Dialog.java:561)

  at java.awt.Component.show(Component.java:1133)

  at java.awt.Component.setVisible(Component.java:1088)

  at com.certusoft.openfoldviewer.Renderer.processSelection(Renderer.java:491)

  at com.certusoft.openfoldviewer.Renderer.display(Renderer.java:151)

  at net.java.games.jogl.impl.GLDrawableHelper.display(GLDrawableHelper.java:74)

  at net.java.games.jogl.GLCanvas$DisplayAction.run(GLCanvas.java:194)

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

  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 net.java.games.jogl.GLCanvas.update(GLCanvas.java:116)

  at sun.awt.RepaintArea.paint(RepaintArea.java:169)

  at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:260)

  at java.awt.Component.dispatchEventImpl(Component.java:3678)

  at java.awt.Component.dispatchEvent(Component.java:3477)

  at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)

  at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)

  at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)

  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)

  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

  at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

Some times, Number of picked object is nonzero, in other words It is picking but the buffer int[] buff is empty in “gl.glSelectBuffer(pickedObjectNumber, buff);”.
Every thing is created and run in display.
Waht I do is not a radikal solution but It might help to uderstand waht is going on. If the buffer is empty when objects are picked, I force the process repeat until the buffer is filled and no more error…
Why is it picking objects but not filling the int[] buff some times(approximately once out of 20)?

???

This is probably no Multithreading issue.

You have created a modal dialog from the display method of your canvas. The event dispatching thread enters a modal event loop and the modal event loop finally calls display from within display. This will not work.

You can either create a non-modal dialog or call show from outside display.

The callstack you posted looks like the dialog is not created from the mouse event but from the repaint event triggered by the mouse event. You should generally avoid creating modal (in fact any) dialogs from repaint events. Try to create the dialog directly from the mouse event. You can also create a seperate event to show your dialog via SwingUtilities.invokeLater.

Thanks, ShadowCaster.
Repaint is triggered in mouse events right before process of picking. I commented the dialog, and just tracing the picking process.
It seems the problem starts with picking. It works fine except the int[] buffer is empty, it is all zero. I create gl,glu all in display.
In short, objects are picked but no information is retrieved.
I will post a small code summarizing the situation.
Thanks.

That is right,
It is a risk to handle a modal dialog.
On the other hand I have to update the data through the canvas screen and right after update new screen and new configuration must be displayed.
What would you suggest instead of a modal dialog?
I would deeply appreciate any hint…
Thanks.