From b7fafd30ffc5eac73880b264043582d74175a394 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 27 Jan 2014 14:12:41 +0100 Subject: Bug 952 - JAWTWindow.JAWTComponentListener's ctor() and detach() may deadlock due to AWTTreeLock acquisition while add/remove AWT listener The AWTTreeLock is acquired by Component.removeHierarchyListener and as for _every_ AWT component, modifications shall happen on the AWT-EDT. IMHO the user shall offload AWT modifications to the AWT-EDT similar to what JOGL's GLCanvas and NEWTCanvasAWT does. However, since JAWTWindow also represents a NativeWindow instance we shall offload AWTTreeLock methods ourselves! --- .../com/jogamp/nativewindow/awt/JAWTWindow.java | 31 +++++++++++++++------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'src/nativewindow/classes/com/jogamp') diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java index a4dfe1c04..a57dafc92 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java @@ -163,19 +163,27 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, private JAWTComponentListener() { isShowing = component.isShowing(); - if(DEBUG) { - System.err.println(jawtStr()+".attach @ Thread "+getThreadName()+": "+toString()); - } - component.addComponentListener(this); - component.addHierarchyListener(this); + AWTEDTExecutor.singleton.invoke(false, new Runnable() { // Bug 952: Avoid deadlock via AWTTreeLock acquisition .. + @Override + public void run() { + if(DEBUG) { + System.err.println(jawtStr()+".attach @ Thread "+getThreadName()+": "+JAWTComponentListener.this.toString()); + } + component.addComponentListener(JAWTComponentListener.this); + component.addHierarchyListener(JAWTComponentListener.this); + } } ); } private final void detach() { - if(DEBUG) { - System.err.println(jawtStr()+".detach @ Thread "+getThreadName()+": "+toString()); - } - component.removeComponentListener(this); - component.removeHierarchyListener(this); + AWTEDTExecutor.singleton.invoke(false, new Runnable() { // Bug 952: Avoid deadlock via AWTTreeLock acquisition .. + @Override + public void run() { + if(DEBUG) { + System.err.println(jawtStr()+".detach @ Thread "+getThreadName()+": "+JAWTComponentListener.this.toString()); + } + component.removeComponentListener(JAWTComponentListener.this); + component.removeHierarchyListener(JAWTComponentListener.this); + } } ); } @Override @@ -601,6 +609,9 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, public void destroy() { surfaceLock.lock(); try { + if(DEBUG) { + System.err.println(jawtStr()+".destroy @ Thread "+getThreadName()); + } jawtComponentListener.detach(); invalidate(); } finally { -- cgit v1.2.3