diff options
author | Sven Gothel <[email protected]> | 2020-03-04 14:42:07 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-03-04 14:42:07 +0100 |
commit | 36ca7245653b1a0897f2070b9acbe0f0898f5949 (patch) | |
tree | 96205bd23f265d347cbbaab09c7f46aa4fe6b9f4 /src/newt | |
parent | 854924c72599aab8d8193b9cb2b85a25bd395a2d (diff) |
OSX/SWT Testing: Drop using 'com.jogamp.newt.util.MainThread' enforcing default test behavior
SWT and OSX's UI TK have their strict threading policy we require to comply with, e.g. see Bug 1398 lately.
It doesn't help using our own MainThread vehicle to move the unit test on the OS main thread,
as this removes potential causes of deadlocks - which we intend to find and resolve.
This patch removed using MainThread altogether from our ant unit testing recipe
as well from our manual test scripts.
Unit tests are no more executed on the 'main thread'.
SWT tests are patched to comply with SWT's UI threading policy.
We also catch violations within NewtCanvasSWT and our SWT GLCanvas
to provide same behavior on all platforms.
Diffstat (limited to 'src/newt')
-rw-r--r-- | src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java | 22 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/swt/event/SWTNewtEventFactory.java | 15 |
2 files changed, 34 insertions, 3 deletions
diff --git a/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java b/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java index ae740bfaa..8ce1eaf2c 100644 --- a/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java +++ b/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java @@ -51,6 +51,7 @@ import jogamp.newt.Debug; import jogamp.newt.swt.SWTEDTUtil; import org.eclipse.swt.SWT; +import org.eclipse.swt.SWTException; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Canvas; @@ -436,9 +437,16 @@ public class NewtCanvasSWT extends Canvas implements NativeWindowHolder, WindowC * <li> Remove reference to the NEWT Child</li> * </ul> * @see Window#destroy() + * @throws SWTException If this method is not called + * {@link SWTAccessor#isOnSWTThread(org.eclipse.swt.widgets.Display) from the SWT thread}, + * an {@link SWTException} is thrown for compliance across platforms. + * User may utilize {@link SWTAccessor#invokeOnSWTThread(org.eclipse.swt.widgets.Display, boolean, Runnable)}. */ @Override - public void dispose() { + public void dispose() throws SWTException { + if( !SWTAccessor.isOnSWTThread( getDisplay() ) ) { + throw new SWTException("Invalid thread access"); + } removeListener (SWT.Paint, swtListener); removeListener (SWT.Move, swtListener); removeListener (SWT.Show, swtListener); @@ -514,8 +522,18 @@ public class NewtCanvasSWT extends Canvas implements NativeWindowHolder, WindowC * via {@link Display#setEDTUtil(EDTUtil)}. * </p> * @return the previous attached newt child. + * + * @throws SWTException If this method is not called + * {@link SWTAccessor#isOnSWTThread(org.eclipse.swt.widgets.Display) from the SWT thread}, + * an {@link SWTException} is thrown for compliance across platforms. + * User may utilize {@link SWTAccessor#invokeOnSWTThread(org.eclipse.swt.widgets.Display, boolean, Runnable)}. */ - public Window setNEWTChild(final Window newChild) { + public Window setNEWTChild(final Window newChild) throws SWTException { + if( !SWTAccessor.isOnSWTThread( getDisplay() ) ) { + throw new SWTException("Invalid thread access"); + } + + // if( org.eclipse.swt.widgets.Display.s) final Window prevChild = newtChild; if(DEBUG) { System.err.println(shortName()+".setNEWTChild.0: win "+newtWinHandleToHexString(prevChild)+" -> "+newtWinHandleToHexString(newChild)); diff --git a/src/newt/classes/jogamp/newt/swt/event/SWTNewtEventFactory.java b/src/newt/classes/jogamp/newt/swt/event/SWTNewtEventFactory.java index bb0b8c1aa..c3fb7d665 100644 --- a/src/newt/classes/jogamp/newt/swt/event/SWTNewtEventFactory.java +++ b/src/newt/classes/jogamp/newt/swt/event/SWTNewtEventFactory.java @@ -30,8 +30,10 @@ package jogamp.newt.swt.event; import com.jogamp.nativewindow.NativeSurface; import com.jogamp.nativewindow.NativeSurfaceHolder; +import com.jogamp.nativewindow.swt.SWTAccessor; import org.eclipse.swt.SWT; +import org.eclipse.swt.SWTException; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; @@ -359,15 +361,26 @@ public class SWTNewtEventFactory { return false; } + /** + * @throws SWTException If this method is not called + * {@link SWTAccessor#isOnSWTThread(org.eclipse.swt.widgets.Display) from the SWT thread}, + * an {@link SWTException} is thrown for compliance across platforms. + * User may utilize {@link SWTAccessor#invokeOnSWTThread(org.eclipse.swt.widgets.Display, boolean, Runnable)}. + */ public final void attachDispatchListener(final org.eclipse.swt.widgets.Control ctrl, final NativeSurfaceHolder sourceHolder, final com.jogamp.newt.event.MouseListener ml, - final com.jogamp.newt.event.KeyListener kl) { + final com.jogamp.newt.event.KeyListener kl) + throws SWTException + { if(null==ctrl) { throw new IllegalArgumentException("Argument ctrl is null"); } if(null==sourceHolder) { throw new IllegalArgumentException("Argument source is null"); } + if( !SWTAccessor.isOnSWTThread( ctrl.getDisplay() ) ) { + throw new SWTException("Invalid thread access"); + } if( null != ml ) { final Listener listener = new Listener () { |