summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-01-22 07:04:11 +0100
committerSven Gothel <[email protected]>2023-01-22 07:04:11 +0100
commit7a352d3747233be44edb4333da108228ca75f0f3 (patch)
tree2511678e0978a74a3e64058d55386c146350f992 /src/test
parentae21ab3e418cb80de10dd1fd265b67bec7d2d31e (diff)
Workaround MacOS + SWT 4.26: java.lang.NullPointerException: Cannot invoke "org.eclipse.swt.internal.cocoa.NSGraphicsContext.saveGraphicsState()" because "context" is null
On MacOS 12+ and SWT 4.26 while not using AWT (-Djava.awt.headless=true, -XstartOnFirstThread), we recently get the following Exception from SWT (suppressed): java.lang.NullPointerException: Cannot invoke "org.eclipse.swt.internal.cocoa.NSGraphicsContext.saveGraphicsState()" because "context" is null at org.eclipse.swt.widgets.Widget.drawRect(Widget.java:764) at org.eclipse.swt.widgets.Canvas.drawRect(Canvas.java:170) at org.eclipse.swt.widgets.Display.windowProc(Display.java:6287) at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method) at org.eclipse.swt.widgets.Display.applicationNextEventMatchingMask(Display.java:5565) at org.eclipse.swt.widgets.Display.applicationProc(Display.java:5965) at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method) at org.eclipse.swt.internal.cocoa.NSApplication.nextEventMatchingMask(NSApplication.java:92) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3983) at com.jogamp.opengl.test.junit.util.SWTTestUtil$WaitAction$1.run(SWTTestUtil.java:52) at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:183) at org.eclipse.swt.widgets.Display.syncExec(Display.java:5250) at com.jogamp.opengl.test.junit.util.SWTTestUtil$WaitAction.run(SWTTestUtil.java:63) at com.jogamp.opengl.test.junit.jogl.acore.TestSharedContextVBOES2SWT3.test02AsyncEachAnimator(TestSharedContextVBOES2SWT3.java:376) This is not observed if running using AWT (-Djava.awt.headless=false).
Diffstat (limited to 'src/test')
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2SWT3.java129
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/swt/TestGearsES2SWT.java55
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/GLTestUtil.java5
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/SWTTestUtil.java21
4 files changed, 143 insertions, 67 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2SWT3.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2SWT3.java
index ba1486010..47e0c579a 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2SWT3.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2SWT3.java
@@ -72,6 +72,28 @@ import org.junit.runners.MethodSorters;
* to initialize all in order, since otherwise the <i>test main thread</i>
* itself blocks SWT GLCanvas creation ..
* </p>
+ * <p>
+ * On MacOS 12+ and SWT 4.26 while not using AWT (-Djava.awt.headless=true, -XstartOnFirstThread),
+ * we recently get the following Exception from SWT (suppressed):
+ * <pre>
+java.lang.NullPointerException: Cannot invoke "org.eclipse.swt.internal.cocoa.NSGraphicsContext.saveGraphicsState()" because "context" is null
+ at org.eclipse.swt.widgets.Widget.drawRect(Widget.java:764)
+ at org.eclipse.swt.widgets.Canvas.drawRect(Canvas.java:170)
+ at org.eclipse.swt.widgets.Display.windowProc(Display.java:6287)
+ at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
+ at org.eclipse.swt.widgets.Display.applicationNextEventMatchingMask(Display.java:5565)
+ at org.eclipse.swt.widgets.Display.applicationProc(Display.java:5965)
+ at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method)
+ at org.eclipse.swt.internal.cocoa.NSApplication.nextEventMatchingMask(NSApplication.java:92)
+ at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3983)
+ at com.jogamp.opengl.test.junit.util.SWTTestUtil$WaitAction$1.run(SWTTestUtil.java:52)
+ at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:183)
+ at org.eclipse.swt.widgets.Display.syncExec(Display.java:5250)
+ at com.jogamp.opengl.test.junit.util.SWTTestUtil$WaitAction.run(SWTTestUtil.java:63)
+ at com.jogamp.opengl.test.junit.jogl.acore.TestSharedContextVBOES2SWT3.test02AsyncEachAnimator(TestSharedContextVBOES2SWT3.java:376)
+ * </pre>
+ * This is not observed if running using AWT (-Djava.awt.headless=false).
+ * </p>
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TestSharedContextVBOES2SWT3 extends UITestCase {
@@ -104,11 +126,13 @@ public class TestSharedContextVBOES2SWT3 extends UITestCase {
@Before
public void init() {
SWTAccessor.invokeOnOSTKThread(true, new Runnable() {
+ @Override
public void run() {
display = new Display();
Assert.assertNotNull( display );
}});
display.syncExec(new Runnable() {
+ @Override
public void run() {
shell1 = new Shell( display );
shell1.setLayout( new FillLayout() );
@@ -138,18 +162,20 @@ public class TestSharedContextVBOES2SWT3 extends UITestCase {
Assert.assertNotNull( composite3 );
try {
display.syncExec(new Runnable() {
- public void run() {
- composite3.dispose();
- shell3.dispose();
- composite2.dispose();
- shell2.dispose();
- composite1.dispose();
- shell1.dispose();
- }});
+ @Override
+ public void run() {
+ composite3.dispose();
+ shell3.dispose();
+ composite2.dispose();
+ shell2.dispose();
+ composite1.dispose();
+ shell1.dispose();
+ }});
SWTAccessor.invokeOnOSTKThread(true, new Runnable() {
- public void run() {
- display.dispose();
- }});
+ @Override
+ public void run() {
+ display.dispose();
+ }});
}
catch( final Throwable throwable ) {
throwable.printStackTrace();
@@ -169,11 +195,12 @@ public class TestSharedContextVBOES2SWT3 extends UITestCase {
Assert.assertNotNull( glCanvas );
glCanvas.addGLEventListener(gears);
display.syncExec(new Runnable() {
- public void run() {
- shell.setText("SWT GLCanvas Shared Gears Test");
- shell.setSize( width, height);
- shell.setLocation(x, y);
- } } );
+ @Override
+ public void run() {
+ shell.setText("SWT GLCanvas Shared Gears Test");
+ shell.setSize( width, height);
+ shell.setLocation(x, y);
+ } } );
return glCanvas;
}
@@ -199,11 +226,12 @@ public class TestSharedContextVBOES2SWT3 extends UITestCase {
animator.add(c3);
display.syncExec(new Runnable() {
- public void run() {
- shell1.open(); // master ..
- shell2.open(); // shall wait until f1 is ready
- shell3.open(); // shall wait until f1 is ready
- } } );
+ @Override
+ public void run() {
+ shell1.open(); // master ..
+ shell2.open(); // shall wait until f1 is ready
+ shell3.open(); // shall wait until f1 is ready
+ } } );
final long t0 = System.currentTimeMillis();
animator.start(); // kicks off GLContext .. and hence gears of f2 + f3 completion
@@ -253,11 +281,12 @@ public class TestSharedContextVBOES2SWT3 extends UITestCase {
Assert.assertEquals(false, animator.isAnimating());
display.syncExec(new Runnable() {
- public void run() {
- c3.dispose();
- c2.dispose();
- c1.dispose();
- } } );
+ @Override
+ public void run() {
+ c3.dispose();
+ c2.dispose();
+ c1.dispose();
+ } } );
}
@Test
@@ -267,19 +296,25 @@ public class TestSharedContextVBOES2SWT3 extends UITestCase {
g1.setSyncObjects(g1); // this is master, since rendered we must use it as sync
// g1.setUseMappedBuffers(useMappedBuffers);
g1.setValidateBuffers(true);
+ System.err.println("TestSharedContextVBOES2SWT3.test02AsyncEachAnimator: 0.0");
final GLCanvas c1 = createGLCanvas(shell1, composite1, 0, 0, g1);
a1.add(c1);
display.syncExec(new Runnable() {
- public void run() {
- shell1.open();
- } } );
+ @Override
+ public void run() {
+ shell1.open();
+ } } );
a1.start();
+ System.err.println("TestSharedContextVBOES2SWT3.test02AsyncEachAnimator: 1.0");
final SWTTestUtil.WaitAction waitAction = new SWTTestUtil.WaitAction(display, true, 200);
Assert.assertEquals(true, GLTestUtil.waitForRealized(c1, true, waitAction));
+ System.err.println("TestSharedContextVBOES2SWT3.test02AsyncEachAnimator: 1.1");
Assert.assertEquals(true, GLTestUtil.waitForContextCreated(c1, true, waitAction));
+ System.err.println("TestSharedContextVBOES2SWT3.test02AsyncEachAnimator: 1.2");
Assert.assertTrue("Gears1 not initialized", g1.waitForInit(true));
+ System.err.println("TestSharedContextVBOES2SWT3.test02AsyncEachAnimator: 2.0");
final Animator a2 = new Animator();
final GearsES2 g2 = new GearsES2(0);
g2.setSharedGears(g1);
@@ -287,11 +322,13 @@ public class TestSharedContextVBOES2SWT3 extends UITestCase {
c2.setSharedAutoDrawable(c1);
a2.add(c2);
display.syncExec(new Runnable() {
- public void run() {
- shell2.open();
- } } );
+ @Override
+ public void run() {
+ shell2.open();
+ } } );
a2.start();
+ System.err.println("TestSharedContextVBOES2SWT3.test02AsyncEachAnimator: 3.0");
final Animator a3 = new Animator();
final GearsES2 g3 = new GearsES2(0);
g3.setSharedGears(g1);
@@ -299,19 +336,27 @@ public class TestSharedContextVBOES2SWT3 extends UITestCase {
c3.setSharedAutoDrawable(c1);
a3.add(c3);
display.syncExec(new Runnable() {
- public void run() {
- shell3.open();
- } } );
+ @Override
+ public void run() {
+ shell3.open();
+ } } );
a3.start();
+ System.err.println("TestSharedContextVBOES2SWT3.test02AsyncEachAnimator: 4.0");
Assert.assertEquals(true, GLTestUtil.waitForRealized(c2, true, waitAction));
+ System.err.println("TestSharedContextVBOES2SWT3.test02AsyncEachAnimator: 4.1: Exception "+(null != waitAction.getException(true)));
Assert.assertEquals(true, GLTestUtil.waitForContextCreated(c2, true, waitAction));
+ System.err.println("TestSharedContextVBOES2SWT3.test02AsyncEachAnimator: 4.2: Exception "+(null != waitAction.getException(true)));
Assert.assertTrue("Gears2 not initialized", g2.waitForInit(true));
+ System.err.println("TestSharedContextVBOES2SWT3.test02AsyncEachAnimator: 5.0: Exception "+(null != waitAction.getException(true)));
Assert.assertEquals(true, GLTestUtil.waitForRealized(c3, true, waitAction));
+ System.err.println("TestSharedContextVBOES2SWT3.test02AsyncEachAnimator: 5.1: Exception "+(null != waitAction.getException(true)));
Assert.assertEquals(true, GLTestUtil.waitForContextCreated(c3, true, waitAction));
+ System.err.println("TestSharedContextVBOES2SWT3.test02AsyncEachAnimator: 5.2: Exception "+(null != waitAction.getException(true)));
Assert.assertTrue("Gears3 not initialized", g3.waitForInit(true));
+ System.err.println("TestSharedContextVBOES2SWT3.test02AsyncEachAnimator: 6.0: Exception "+(null != waitAction.getException(true)));
final long t0 = System.currentTimeMillis();
final GLContext ctx1 = c1.getContext();
@@ -340,6 +385,7 @@ public class TestSharedContextVBOES2SWT3 extends UITestCase {
while(System.currentTimeMillis()-t0<duration) {
waitAction.run();
}
+ System.err.println("TestSharedContextVBOES2SWT3.test02AsyncEachAnimator: 8.0: Exception "+(null != waitAction.getException(true)));
// Stopped animator allows native windowing system 'repaint' event
// to trigger GLAD 'display'
a1.stop();
@@ -350,14 +396,15 @@ public class TestSharedContextVBOES2SWT3 extends UITestCase {
Assert.assertEquals(false, a3.isAnimating());
display.syncExec(new Runnable() {
- public void run() {
- c3.dispose();
- c2.dispose();
- c1.dispose();
- } } );
+ @Override
+ public void run() {
+ c3.dispose();
+ c2.dispose();
+ c1.dispose();
+ } } );
}
- static long duration = 1000; // ms
+ static long duration = 2000; // ms
public static void main(final String args[]) {
for(int i=0; i<args.length; i++) {
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/swt/TestGearsES2SWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/swt/TestGearsES2SWT.java
index 9ca6577b0..0b2d42bcf 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/swt/TestGearsES2SWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/swt/TestGearsES2SWT.java
@@ -102,11 +102,13 @@ public class TestGearsES2SWT extends UITestCase {
@Before
public void init() {
SWTAccessor.invokeOnOSTKThread(true, new Runnable() {
+ @Override
public void run() {
display = new Display();
Assert.assertNotNull( display );
}});
display.syncExec(new Runnable() {
+ @Override
public void run() {
shell = new Shell( display );
Assert.assertNotNull( shell );
@@ -124,14 +126,16 @@ public class TestGearsES2SWT extends UITestCase {
Assert.assertNotNull( composite );
try {
display.syncExec(new Runnable() {
- public void run() {
- composite.dispose();
- shell.dispose();
- }});
+ @Override
+ public void run() {
+ composite.dispose();
+ shell.dispose();
+ }});
SWTAccessor.invokeOnOSTKThread(true, new Runnable() {
- public void run() {
- display.dispose();
- }});
+ @Override
+ public void run() {
+ display.dispose();
+ }});
}
catch( final Throwable throwable ) {
throwable.printStackTrace();
@@ -162,28 +166,33 @@ public class TestGearsES2SWT extends UITestCase {
Assert.assertEquals(exclusiveContext ? animator.getThread() : null, canvas.getExclusiveContextThread());
display.syncExec( new Runnable() {
- public void run() {
- shell.setText( getSimpleTestName(".") );
- shell.setSize( wsize.getWidth(), wsize.getHeight() );
- if( null != wpos ) {
- shell.setLocation( wpos.getX(), wpos.getY() );
- }
- shell.open();
- }
+ @Override
+ public void run() {
+ shell.setText( getSimpleTestName(".") );
+ shell.setSize( wsize.getWidth(), wsize.getHeight() );
+ if( null != wpos ) {
+ shell.setLocation( wpos.getX(), wpos.getY() );
+ }
+ shell.open();
+ }
});
animator.setUpdateFPSFrames(60, showFPS ? System.err : null);
final SWTTestUtil.WaitAction waitAction = new SWTTestUtil.WaitAction(display, true, 16);
+ System.err.println("TestGearsES2SWT.test: 2.0: Exception "+(null != waitAction.getException(true)));
Assert.assertEquals(true, GLTestUtil.waitForRealized(canvas, true, waitAction));
+ System.err.println("TestGearsES2SWT.test: 2.1: Exception "+(null != waitAction.getException(true)));
while(animator.isAnimating() && !canvas.isRealized() && animator.getTotalFPSDuration()<duration) {
waitAction.run();
}
+ System.err.println("TestGearsES2SWT.test: 3.0: Exception "+(null != waitAction.getException(true)));
System.err.println("NW chosen: "+canvas.getDelegatedDrawable().getChosenGLCapabilities());
System.err.println("GL chosen: "+canvas.getChosenGLCapabilities());
display.syncExec(new Runnable() {
+ @Override
public void run() {
System.err.println("window pos/siz: "+canvas.getLocation()+" "+canvas.getSurfaceWidth()+"x"+canvas.getSurfaceHeight());
} } );
@@ -192,10 +201,12 @@ public class TestGearsES2SWT extends UITestCase {
for(int i=0; i<50; i++) { // 500 ms dispatched delay
waitAction.run();
}
+ System.err.println("TestGearsES2SWT.test: 4.0: Exception "+(null != waitAction.getException(true)));
display.syncExec( new Runnable() {
- public void run() {
- shell.setSize( rwsize.getWidth(), rwsize.getHeight() );
- }
+ @Override
+ public void run() {
+ shell.setSize( rwsize.getWidth(), rwsize.getHeight() );
+ }
});
System.err.println("window resize pos/siz: "+canvas.getLocation()+" "+canvas.getSurfaceWidth()+"x"+canvas.getSurfaceHeight());
}
@@ -203,6 +214,7 @@ public class TestGearsES2SWT extends UITestCase {
while(animator.isAnimating() && animator.getTotalFPSDuration()<duration) {
waitAction.run();
}
+ System.err.println("TestGearsES2SWT.test: 5.0: Exception "+(null != waitAction.getException(true)));
Assert.assertEquals(exclusiveContext ? animator.getThread() : null, canvas.getExclusiveContextThread());
animator.stop();
@@ -211,9 +223,10 @@ public class TestGearsES2SWT extends UITestCase {
Assert.assertEquals(null, canvas.getExclusiveContextThread());
display.syncExec(new Runnable() {
- public void run() {
- canvas.dispose();
- } } );
+ @Override
+ public void run() {
+ canvas.dispose();
+ } } );
}
@Test
diff --git a/src/test/com/jogamp/opengl/test/junit/util/GLTestUtil.java b/src/test/com/jogamp/opengl/test/junit/util/GLTestUtil.java
index 792dfa831..323cbb537 100644
--- a/src/test/com/jogamp/opengl/test/junit/util/GLTestUtil.java
+++ b/src/test/com/jogamp/opengl/test/junit/util/GLTestUtil.java
@@ -99,7 +99,10 @@ public class GLTestUtil extends TestUtil {
}
t1 = System.currentTimeMillis();
}
- return (t1-t0) < TIME_OUT;
+ final boolean to = (t1-t0) >= TIME_OUT;
+ final boolean ok = realized == glad.isRealized();
+ System.err.println("waitForRealized: to "+to+", goal reached "+ok);
+ return !to || ok;
}
}
diff --git a/src/test/com/jogamp/opengl/test/junit/util/SWTTestUtil.java b/src/test/com/jogamp/opengl/test/junit/util/SWTTestUtil.java
index 5e80bacaa..91e4d603d 100644
--- a/src/test/com/jogamp/opengl/test/junit/util/SWTTestUtil.java
+++ b/src/test/com/jogamp/opengl/test/junit/util/SWTTestUtil.java
@@ -38,6 +38,7 @@ public class SWTTestUtil {
final Display display;
final boolean blocking;
final long sleepMS;
+ volatile Exception exo = null;
public WaitAction(final Display display, final boolean blocking, final long sleepMS) {
this.display = display;
@@ -57,12 +58,24 @@ public class SWTTestUtil {
@Override
public void run() {
- if( blocking ) {
- display.syncExec( waitAction0 );
- } else {
- display.asyncExec( waitAction0 );
+ try {
+ if( blocking ) {
+ display.syncExec( waitAction0 );
+ } else {
+ display.asyncExec( waitAction0 );
+ }
+ } catch (final Exception ex) {
+ ex.printStackTrace();
+ exo = ex;
}
};
+ public Exception getException(final boolean clear) {
+ final Exception r = exo;
+ if( clear ) {
+ exo = null;
+ }
+ return r;
+ }
}
public static class WaitAction2 implements Runnable {