Picking deadlock with GLJPanel

Hi,

I tried to implement picking objects on a GLJPanel using the selection buffer, but my code invariably produces a deadlock.

What I need to have is a method, that works like this:

public SelectableObject pick(Point mouseLocation);

To implement this method, I firts store the mouse location in a global variable and then call display() on the glJPanel.

JOGL should then callback the display(Drawable) method of my GLEventListener, where I change the renderMode to GL_SELCET, draw all Objects, read the selection buffer and finally store the results in a global variable.

When the display call on GLJPanel returns, I want to read the selection results from the global variable and return the selected object to the caller of my pick method.

My Problem is: calling display() on GLJPanel from the AWT-EventDispatchingThread causes an immidiate deadlock.

Here is the respective code from GLJPanel.

public void display() {
// Multithreaded redrawing of Swing
// components is not allowed
try {
synchronized(semaphore) {
repaintDone = false;
repaint();
while (!repaintDone) {
semaphore.wait();
}
}
} catch (InterruptedException e) {
}
}

The reason for the deadlock is obvious: the repaint is triggered but can never be executed, because the only thread executing repaints is the thread waiting for them.

The same procedure for selction works fine with GLCanvas.

I have two Questions and would be especially glad, if anyone could answer the first one:

  1. Does anyone know a working solution to implement the my pick method for a swing gui without running into deadlocks? The method must be callable from the AWT-EventDispatchingThread and I need to have the result as a return value of the method.

  2. Why doesn’t display check, whether the current thread is already the AWT-EventDispatchingThread? The repaint could be done immidiately in this case.

Hi,

I implemented GL_SELECT-based picking for Xith3D, and it is working well.

I use synchronized flags and wait/notify to inform rendering thread (which is NOT the AWT event handling thread) about the fact I want to pick the point.

Xith3D calls setNoAutoRedrawMode(true) on drawable, so it does not use repaint() to perform drawing operation.

Yuri

But how can I make this rendering thread actually perform the rendering on my panel?

If I simply try to call display, it will trigger a repaint() and the repaint manager will put an event on the AWT-Queue, where it causes rendering fom the AWT-Thread.

Additionally, all calls to setAutoRedraw are simply ignored by GLJPanel (I checked this in source, the method is empty).

Well, I am using GLCanvas, not GLJpanel… in that case call to display() makes expected things, i.e. enforces scene redraw.

Yuri