diff options
author | Sven Gothel <[email protected]> | 2013-03-14 10:48:44 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-03-14 10:48:44 +0100 |
commit | 896e8b021b39e9415040a57a1d540d7d24b02db1 (patch) | |
tree | c031248b4a464602aaa150b4d088235b9db065f0 /src/test | |
parent | 58f6f4e5665ae2c72ec6bbd86ad5a36bef00de07 (diff) |
OSX/CALayer: Revise CALayer 'RunOnMainThread' utilization, avoiding deadlocks
RunOnMainThread(waitUntilDone:=true,..) can deadlock the main-thread if called from AWT-EDT,
since the main-thread may call back to AWT-EDT while injecting a new main-thread task.
This patch revises all RunOnMainThread CALayer usage, resulting in only one required left:
- OSXUtil.AddCASublayer() w/ waitUntilDone:=false
Hence the CALayer code has no more potential to deadlock main-thread/AWT-EDT.
OSXUtil.AddCASublayer() must be performed on main-thread, otherwise the
CALayer attachment will fail - no visible rendering result.
+++
Note: A good trigger to test this deadlock is to magnify/zoom
the OSX desktop (click background + ctrl-mouse_wheel)
before running some unit tests.
TestGLCanvasAWTActionDeadlock01AWT and TestAddRemove02GLWindowNewtCanvasAWT
also have the potential to trigger the mentioned deadlock.
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2AWT.java | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2AWT.java index d59b81ff1..64151362b 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2AWT.java @@ -77,6 +77,7 @@ public class TestGearsES2AWT extends UITestCase { static boolean shutdownSystemExit = false; static int swapInterval = 1; static boolean exclusiveContext = false; + static boolean useAnimator = true; static Thread awtEDT; static Dimension rwsize = null; @@ -167,8 +168,8 @@ public class TestGearsES2AWT extends UITestCase { glCanvas.addGLEventListener(new GearsES2(swapInterval)); - Animator animator = new Animator(glCanvas); - if( exclusiveContext ) { + final Animator animator = useAnimator ? new Animator(glCanvas) : null; + if( useAnimator && exclusiveContext ) { animator.setExclusiveContext(awtEDT); } QuitAdapter quitAdapter = new QuitAdapter(); @@ -184,11 +185,13 @@ public class TestGearsES2AWT extends UITestCase { Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true)); Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas, true)); - animator.start(); - Assert.assertTrue(animator.isStarted()); - Assert.assertTrue(animator.isAnimating()); - Assert.assertEquals(exclusiveContext ? awtEDT : null, glCanvas.getExclusiveContextThread()); - animator.setUpdateFPSFrames(60, System.err); + if( useAnimator ) { + animator.start(); + Assert.assertTrue(animator.isStarted()); + Assert.assertTrue(animator.isAnimating()); + Assert.assertEquals(exclusiveContext ? awtEDT : null, glCanvas.getExclusiveContextThread()); + animator.setUpdateFPSFrames(60, System.err); + } System.err.println("canvas pos/siz: "+glCanvas.getX()+"/"+glCanvas.getY()+" "+glCanvas.getWidth()+"x"+glCanvas.getHeight()); @@ -198,19 +201,25 @@ public class TestGearsES2AWT extends UITestCase { System.err.println("window resize pos/siz: "+glCanvas.getX()+"/"+glCanvas.getY()+" "+glCanvas.getWidth()+"x"+glCanvas.getHeight()); } - while(!quitAdapter.shouldQuit() /* && animator.isAnimating() */ && animator.getTotalFPSDuration()<duration) { + final long t0 = System.currentTimeMillis(); + long t1 = t0; + while(!quitAdapter.shouldQuit() && t1 - t0 < duration) { Thread.sleep(100); + t1 = System.currentTimeMillis(); } Assert.assertNotNull(frame); Assert.assertNotNull(glCanvas); - Assert.assertNotNull(animator); + + if( useAnimator ) { + Assert.assertNotNull(animator); + Assert.assertEquals(exclusiveContext ? awtEDT : null, glCanvas.getExclusiveContextThread()); + animator.stop(); + Assert.assertFalse(animator.isAnimating()); + Assert.assertFalse(animator.isStarted()); + Assert.assertEquals(null, glCanvas.getExclusiveContextThread()); + } - Assert.assertEquals(exclusiveContext ? awtEDT : null, glCanvas.getExclusiveContextThread()); - animator.stop(); - Assert.assertFalse(animator.isAnimating()); - Assert.assertFalse(animator.isStarted()); - Assert.assertEquals(null, glCanvas.getExclusiveContextThread()); javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { frame.setVisible(false); @@ -288,6 +297,8 @@ public class TestGearsES2AWT extends UITestCase { swapInterval = MiscUtils.atoi(args[i], swapInterval); } else if(args[i].equals("-exclctx")) { exclusiveContext = true; + } else if(args[i].equals("-noanim")) { + useAnimator = false; } else if(args[i].equals("-layeredFBO")) { shallUseOffscreenFBOLayer = true; } else if(args[i].equals("-layeredPBuffer")) { @@ -319,6 +330,8 @@ public class TestGearsES2AWT extends UITestCase { System.err.println("forceGL3 "+forceGL3); System.err.println("swapInterval "+swapInterval); System.err.println("exclusiveContext "+exclusiveContext); + System.err.println("useAnimator "+useAnimator); + System.err.println("shallUseOffscreenFBOLayer "+shallUseOffscreenFBOLayer); System.err.println("shallUseOffscreenPBufferLayer "+shallUseOffscreenPBufferLayer); |