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:
-
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.
-
Why doesn’t display check, whether the current thread is already the AWT-EventDispatchingThread? The repaint could be done immidiately in this case.