diff options
author | Sven Gothel <[email protected]> | 2013-11-25 22:08:50 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-11-25 22:08:50 +0100 |
commit | 1617b3edfa006432dbb7332c283e219e6583f4ec (patch) | |
tree | 6c3f21b5b4e7a0d6d86778df17120a05cac2dfaa | |
parent | d5c25aa5584e98416208afef57610c85ac6c254c (diff) |
Workaround Bug 910 (IcedTea-Web): NewtCanvasAWT shall postpone JAWTWindow destruction via explicit set flag.
IcedTea-Web_1.5pre+rbc73a1362e9c still issues NewtCanvasAWT.removeNotify()
before before Applet.destroy(), i.e. removes NewtCanvasAWT from the Container
ahead of time (Applet protocol destroy()).
However, it fixes the non AWT-EDT issue, i.e. calls NewtCanvasAWT.removeNotify()
from the actual AWT-EDT - good.
Since the root cause still exist, we cannot use heuristics as described in
Bug 910 comment 9, but need to set a flag in NewtCanvasAWT to skip JAWT destruction
and remove it latter within Applet.destroy().
NewtCanvasAWT.removeNotify.0 - isApplet true @ [AWT-EventQueue-0, isAWT-EDT true]
-rw-r--r-- | src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java | 43 | ||||
-rw-r--r-- | src/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtApplet1Run.java | 2 |
2 files changed, 25 insertions, 20 deletions
diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java index 9c66daf1c..b6b8cf9e8 100644 --- a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java +++ b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java @@ -108,10 +108,10 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto private final AWTAdapter awtMouseAdapter; private final AWTAdapter awtKeyAdapter; - /** Mitigates Bug 910 (IcedTea-Web), i.e. crash via removeNotify() from 'other' AWT-EDT. */ - private boolean addedOnAWTEDT = false; - /** Mitigates Bug 910 (IcedTea-Web), i.e. crash via removeNotify() from 'other' AWT-EDT. */ + /** Mitigates Bug 910 (IcedTea-Web), i.e. crash via removeNotify() invoked before Applet.destroy(). */ private boolean destroyJAWTPending = false; + /** Mitigates Bug 910 (IcedTea-Web), i.e. crash via removeNotify() invoked before Applet.destroy(). */ + private boolean skipJAWTDestroy = false; /** Safeguard for AWTWindowClosingProtocol and 'removeNotify()' on other thread than AWT-EDT. */ private volatile boolean componentAdded = false; @@ -425,6 +425,20 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto return awtWindowClosingProtocol.setDefaultCloseOperation(op); } + /** + * Mitigates Bug 910 (IcedTea-Web), i.e. crash via removeNotify() invoked before Applet.destroy(). + * <p> + * <code>skipJAWTDestroy</code> defaults to <code>false</code>. + * Due to above IcedTea-Web issue the <code>Applet</code> code needs to avoid JAWT destruction before + * <code>Applet.destroy()</code> is reached by setting <code>skipJAWTDestroy</code> to <code>true</code>. + * Afterwards the value should be reset to <code>false</code> and {@link #destroy()} needs to be called, + * which finally will perform the pending JAWT destruction. + * </p> + */ + public final void setSkipJAWTDestroy(boolean v) { skipJAWTDestroy = v; } + /** See {@link #setSkipJAWTDestroy(boolean)}. */ + public final boolean getSkipJAWTDestroy() { return skipJAWTDestroy; } + private final void determineIfApplet() { isApplet = false; Component c = this; @@ -450,9 +464,8 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto synchronized(sync) { determineIfApplet(); - addedOnAWTEDT = EventQueue.isDispatchThread(); if(DEBUG) { - System.err.println("NewtCanvasAWT.addNotify.0 - isApplet "+isApplet+", addedOnAWTEDT "+addedOnAWTEDT+" @ "+currentThreadName()); + System.err.println("NewtCanvasAWT.addNotify.0 - isApplet "+isApplet+", addedOnAWTEDT "+EventQueue.isDispatchThread()+" @ "+currentThreadName()); Thread.dumpStack(); } jawtWindow = NewtFactoryAWT.getNativeWindow(NewtCanvasAWT.this, null != newtChild ? newtChild.getRequestedCapabilities() : null); @@ -514,18 +527,9 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto private final void destroyImpl(boolean removeNotify, boolean windowClosing) { synchronized(sync) { final java.awt.Container cont = AWTMisc.getContainer(this); - /** - * Mitigates Bug 910 (IcedTea-Web), i.e. crash via removeNotify() from 'other' AWT-EDT. - * - * 'destroyJAWT' defaults to 'true' - however, IcedTea-Web (Applet) issues removeNotify() from - * a different AWT-EDT thread, which is not recognized as an AWT-EDT thread! - * This 'different AWT-EDT thread' maybe caused due to a AppContext issue in IcedTea-Web. - */ - final boolean isOnAWTEDT = EventQueue.isDispatchThread(); - final boolean destroyJAWTOK = !isApplet || !addedOnAWTEDT || isOnAWTEDT; if(DEBUG) { System.err.println("NewtCanvasAWT.destroyImpl @ "+currentThreadName()); - System.err.println("NewtCanvasAWT.destroyImpl.0 - isApplet "+isApplet+", addedOnAWTEDT "+addedOnAWTEDT+", isOnAWTEDT "+isOnAWTEDT+" -> destroyJAWTOK "+destroyJAWTOK+ + System.err.println("NewtCanvasAWT.destroyImpl.0 - isApplet "+isApplet+", isOnAWTEDT "+EventQueue.isDispatchThread()+", skipJAWTDestroy "+skipJAWTDestroy+ "; removeNotify "+removeNotify+", windowClosing "+windowClosing+", destroyJAWTPending "+destroyJAWTPending+ ", hasJAWT "+(null!=jawtWindow)+", hasNEWT "+(null!=newtChild)+ "): nw "+newtWinHandleToHexString(newtChild)+", from "+cont); @@ -545,14 +549,13 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto } } if( ( destroyJAWTPending || removeNotify || windowClosing ) && null!=jawtWindow ) { - if( destroyJAWTOK ) { + if( skipJAWTDestroy ) { + // Bug 910 - See setSkipJAWTDestroy(boolean) + destroyJAWTPending = true; + } else { NewtFactoryAWT.destroyNativeWindow(jawtWindow); jawtWindow=null; destroyJAWTPending = false; - } else { - // Bug 910 - See above FIXME - destroyJAWTPending = true; - System.err.println("Info: JAWT destruction pending due to: isApplet "+isApplet+", addedOnAWTEDT "+addedOnAWTEDT+", isOnAWTEDT "+isOnAWTEDT+" -> destroyJAWTOK "+destroyJAWTOK); } } } diff --git a/src/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtApplet1Run.java b/src/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtApplet1Run.java index 0bdc70586..74d4d833a 100644 --- a/src/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtApplet1Run.java +++ b/src/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtApplet1Run.java @@ -220,6 +220,7 @@ public class JOGLNewtApplet1Run extends Applet { AWTEDTExecutor.singleton.invoke(true, new Runnable() { public void run() { newtCanvasAWT = new NewtCanvasAWT(glWindow); + newtCanvasAWT.setSkipJAWTDestroy(true); // Bug 910 container.add(newtCanvasAWT, BorderLayout.CENTER); container.validate(); } } ); @@ -307,6 +308,7 @@ public class JOGLNewtApplet1Run extends Applet { public void run() { glWindow.setVisible(false); // hide 1st if( null != newtCanvasAWT ) { + newtCanvasAWT.setSkipJAWTDestroy(false); // Bug 910 remove(newtCanvasAWT); // remove newtCanvasAWT incl. glWindow.reparentWindow(null) if not done yet! newtCanvasAWT.destroy(); } |