aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/com/jogamp/opengl
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-06-12 08:20:38 +0200
committerSven Gothel <[email protected]>2014-06-12 08:20:38 +0200
commit5626740d14554acf7a17a73ec12b0893445832d0 (patch)
treef2d68b4df87f0ecc1946d72e3d84f0b3587d2798 /src/test/com/jogamp/opengl
parent94de08a2b0661d072324677c729fc8d1b3d0ef0f (diff)
Fix Bug 1019 - Remedy of Bug 691 causes 'access/modify after free' and crashes the app
The 'magic' MyNSOpenGLContext::dealloc (MacOSXWindowSystemInterface-calayer.m) of force destroying the underlying CGLContextObj of it's associated NSOpenGLContext as introduced as a remedy of Bug 691 is plain wrong. It was added in commit f6e6fab2a7ddfb5c9b614cb072c27ff697629161 to mitigate the experience behavior of delayed GL context destruction when creating/destroying them multiple times as exposed in unit test TestGLCanvasAddRemove01SwingAWT. While this 'hack' worked for some reason on some OSX versions, it caused a 'access/modify after free' issue exposed under some circumstances and crashes the application. The actual culprit of the delayed GL context destruction is different. The offthread CALayer detachment and hence final destruction issued on the main-thread is _not_ issued immediately due to some referencing holding by NSApp. Issuing an empty event on the NSApp (thread) will wake up the thread and release claimed resources. This has been found while realizing that the GL context are released if the mouse is being moved (duh!). This issue is also known when triggering stop on the NSApp (NEWT MainThread), same remedy has been implemented here for a long time.
Diffstat (limited to 'src/test/com/jogamp/opengl')
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestAddRemove01GLCanvasSwingAWT.java80
1 files changed, 40 insertions, 40 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestAddRemove01GLCanvasSwingAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestAddRemove01GLCanvasSwingAWT.java
index 3e54bcd60..8dfd93e47 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestAddRemove01GLCanvasSwingAWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestAddRemove01GLCanvasSwingAWT.java
@@ -3,14 +3,14 @@
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
- *
+ *
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
- *
+ *
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
@@ -20,12 +20,12 @@
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
+ *
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of JogAmp Community.
*/
-
+
package com.jogamp.opengl.test.junit.jogl.acore;
import java.awt.AWTException;
@@ -88,9 +88,9 @@ public class TestAddRemove01GLCanvasSwingAWT extends UITestCase {
@AfterClass
public static void releaseClass() {
}
-
- protected JPanel create(final JFrame[] top, final int width, final int height, final int num)
- throws InterruptedException, InvocationTargetException
+
+ protected JPanel create(final JFrame[] top, final int width, final int height, final int num)
+ throws InterruptedException, InvocationTargetException
{
final JPanel[] jPanel = new JPanel[] { null };
SwingUtilities.invokeAndWait(new Runnable() {
@@ -103,30 +103,30 @@ public class TestAddRemove01GLCanvasSwingAWT extends UITestCase {
jFrame1.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // equivalent to Frame, use windowClosing event!
jFrame1.getContentPane().add(jPanel[0]);
jFrame1.setSize(width, height);
-
+
top[0] = jFrame1;
} } );
- return jPanel[0];
+ return jPanel[0];
}
- protected void add(final Container cont, final Component comp)
- throws InterruptedException, InvocationTargetException
+ protected void add(final Container cont, final Component comp)
+ throws InterruptedException, InvocationTargetException
{
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
- cont.add(comp, BorderLayout.CENTER);
+ cont.add(comp, BorderLayout.CENTER);
} } );
}
-
- protected void dispose(final GLCanvas glc)
- throws InterruptedException, InvocationTargetException
+
+ protected void dispose(final GLCanvas glc)
+ throws InterruptedException, InvocationTargetException
{
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
- glc.destroy();
+ glc.destroy();
} } );
}
-
+
protected void setVisible(final JFrame jFrame, final boolean visible) throws InterruptedException, InvocationTargetException {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
@@ -135,25 +135,25 @@ public class TestAddRemove01GLCanvasSwingAWT extends UITestCase {
jFrame.validate();
}
jFrame.setVisible(visible);
- } } ) ;
+ } } ) ;
}
-
+
protected void dispose(final JFrame jFrame) throws InterruptedException, InvocationTargetException {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
jFrame.dispose();
- } } ) ;
+ } } ) ;
}
-
+
protected void runTestGL(boolean onscreen, GLCapabilities caps, int addRemoveOpCount)
throws AWTException, InterruptedException, InvocationTargetException
{
-
if(waitForKey) {
UITestCase.waitForKey("Start");
- }
+ }
for(int i=0; i<addRemoveOpCount; i++) {
- System.err.println("Loop # "+i+" / "+addRemoveCount);
+ int ti = 0;
+ System.err.println("Loop."+(ti++)+" "+(i+1)+"/"+addRemoveOpCount);
final GLCanvas glc = new GLCanvas(caps);
Assert.assertNotNull(glc);
if( !onscreen ) {
@@ -166,23 +166,23 @@ public class TestAddRemove01GLCanvasSwingAWT extends UITestCase {
final GearsES2 gears = new GearsES2(1);
gears.setVerbose(false);
glc.addGLEventListener(gears);
-
+
final JFrame[] top = new JFrame[] { null };
final Container glcCont = create(top, width, height, i);
add(glcCont, glc);
-
+
setVisible(top[0], true);
-
+
final long t0 = System.currentTimeMillis();
do {
glc.display();
Thread.sleep(10);
} while ( ( System.currentTimeMillis() - t0 ) < durationPerTest ) ;
-
- System.err.println("GLCanvas isOffscreenLayerSurfaceEnabled: "+glc.isOffscreenLayerSurfaceEnabled()+": "+glc.getChosenGLCapabilities());
-
+
+ System.err.println("Loop."+(ti++)+" "+(i+1)+"/"+addRemoveOpCount+": GLCanvas isOffscreenLayerSurfaceEnabled: "+glc.isOffscreenLayerSurfaceEnabled()+": "+glc.getChosenGLCapabilities());
+
dispose(top[0]);
-
+
if( 0 < pauseEach && 0 == i % pauseEach ) {
System.err.println("******* P A U S E - Start ********");
// OSXUtil.WaitUntilFinish();
@@ -192,7 +192,7 @@ public class TestAddRemove01GLCanvasSwingAWT extends UITestCase {
}
if(waitForKeyPost) {
UITestCase.waitForKey("End");
- }
+ }
}
@Test
@@ -226,7 +226,7 @@ public class TestAddRemove01GLCanvasSwingAWT extends UITestCase {
}
runTestGL(false, caps, addRemoveCount);
}
-
+
@Test
public void test03OffscreenPBuffer()
throws AWTException, InterruptedException, InvocationTargetException
@@ -244,7 +244,7 @@ public class TestAddRemove01GLCanvasSwingAWT extends UITestCase {
caps.setOnscreen(true); // simulate normal behavior ..
runTestGL(false, caps, addRemoveCount);
}
-
+
public static void main(String args[]) throws IOException {
for(int i=0; i<args.length; i++) {
if(args[i].equals("-time")) {
@@ -277,16 +277,16 @@ public class TestAddRemove01GLCanvasSwingAWT extends UITestCase {
}
System.err.println("waitForKey "+waitForKey);
System.err.println("waitForKeyPost "+waitForKeyPost);
-
+
System.err.println("addRemoveCount "+addRemoveCount);
System.err.println("pauseEach "+pauseEach);
- System.err.println("pauseDuration "+pauseDuration);
-
+ System.err.println("pauseDuration "+pauseDuration);
+
System.err.println("noOnscreenTest "+noOnscreenTest);
System.err.println("noOffscreenTest "+noOffscreenTest);
System.err.println("offscreenPBufferOnly "+offscreenPBufferOnly);
System.err.println("offscreenFBOOnly "+offscreenFBOOnly);
-
- org.junit.runner.JUnitCore.main(TestAddRemove01GLCanvasSwingAWT.class.getName());
+
+ org.junit.runner.JUnitCore.main(TestAddRemove01GLCanvasSwingAWT.class.getName());
}
}