@@ -101,8 +101,8 @@ public class PSurfaceJOGL implements PSurface {
101101 protected Object waitObject = new Object ();
102102
103103 protected NewtCanvasAWT canvas ;
104- protected boolean placedWindow = false ;
105- protected boolean requestedStart = false ;
104+ // protected boolean placedWindow = false;
105+ // protected boolean requestedStart = false;
106106
107107 protected float [] currentPixelScale = {0 , 0 };
108108
@@ -341,7 +341,7 @@ protected void initWindow() {
341341 if (fullScreen ) {
342342 PApplet .hideMenuBar ();
343343 window .setTopLevelPosition (sketchX , sketchY );
344- placedWindow = true ;
344+ // placedWindow = true;
345345 if (spanDisplays ) {
346346 window .setFullscreen (monitors );
347347 } else {
@@ -395,6 +395,8 @@ public void run() {
395395// throw (ThreadDeath)cause;
396396 } else if (cause instanceof RuntimeException ) {
397397 throw (RuntimeException )cause ;
398+ } else if (cause instanceof UnsatisfiedLinkError ) {
399+ throw new UnsatisfiedLinkError (cause .getMessage ());
398400 } else {
399401 throw new RuntimeException (cause );
400402 }
@@ -417,34 +419,13 @@ public void run() {
417419
418420
419421 @ Override
420- public void setVisible (boolean visible ) {
421- try {
422- window .setVisible (visible );
423- } catch (Exception ex ) {
424- Throwable glex = ex .getCause ();
425- if (glex instanceof GLException ) {
426- Throwable cause = glex .getCause ();
427- if (cause instanceof UnsatisfiedLinkError ) {
428- // https://github.com/processing/processing/issues/3453
429- // Special handling of missing libraries, for some reason throwing
430- // the cause still show the entire stack, including the enclosing
431- // exceptions from JOGL.
432- throw new UnsatisfiedLinkError (cause .getMessage ());
433- } else {
434- try {
435- throw cause ;
436- } catch (Throwable e ) {
437- // TODO Auto-generated catch block
438- e .printStackTrace ();
439- }
440- } if (cause instanceof RuntimeException ) {
441- throw (RuntimeException )cause ;
442- } else {
443- throw new RuntimeException (cause );
444- }
422+ public void setVisible (final boolean visible ) {
423+ display .getEDTUtil ().invoke (false , new Runnable () {
424+ @ Override
425+ public void run () {
426+ window .setVisible (visible );
445427 }
446- throw ex ;
447- }
428+ });
448429 }
449430
450431
@@ -465,8 +446,13 @@ public void setIcon(PImage icon) {
465446
466447
467448 @ Override
468- public void setAlwaysOnTop (boolean always ) {
469- window .setAlwaysOnTop (always );
449+ public void setAlwaysOnTop (final boolean always ) {
450+ display .getEDTUtil ().invoke (false , new Runnable () {
451+ @ Override
452+ public void run () {
453+ window .setAlwaysOnTop (always );
454+ }
455+ });
470456 }
471457
472458
@@ -555,8 +541,8 @@ public void placeWindow(int[] location, int[] editorLocation) {
555541 window .setTopLevelPosition (frameLoc .x , 30 );
556542 }
557543
558- placedWindow = true ;
559- if (requestedStart ) startThread ();
544+ // placedWindow = true;
545+ // if (requestedStart) startThread();
560546// canvas.setBounds((contentW - sketchWidth)/2,
561547// (contentH - sketchHeight)/2,
562548// sketchWidth, sketchHeight);
@@ -580,9 +566,8 @@ public void placePresent(int stopColor) {
580566 sketchY + screenRect .y );
581567// window.setTopLevelPosition(0, 0);
582568 window .setFullscreen (true );
583- placedWindow = true ;
584- if (requestedStart ) startThread ();
585-
569+ // placedWindow = true;
570+ // if (requestedStart) startThread();
586571// }
587572 }
588573
@@ -595,21 +580,7 @@ public void setupExternalMessages() {
595580
596581 public void startThread () {
597582 if (animator != null ) {
598- if (placedWindow ) {
599- window .setVisible (true );
600- animator .start ();
601- requestedStart = false ;
602- } else {
603- // The GL window is not visible until it has been placed, so we cannot
604- // start the animator because it requires the window to be visible.
605- requestedStart = true ;
606- // Need this assignment to bypass the while loop in runSketch, otherwise
607- // the programs hangs waiting for defaultSize to be false, but it never
608- // happens because the animation thread is not yet running to avoid showing
609- // the window in the wrong place:
610- // https://github.com/processing/processing/issues/3308
611- // sketch.defaultSize = false;
612- }
583+ animator .start ();
613584 }
614585 }
615586
@@ -646,14 +617,17 @@ public boolean isStopped() {
646617 }
647618
648619
649- public void setLocation (int x , int y ) {
650- if (window != null ) {
651- window .setTopLevelPosition (x , y );
652- }
620+ public void setLocation (final int x , final int y ) {
621+ display .getEDTUtil ().invoke (false , new Runnable () {
622+ @ Override
623+ public void run () {
624+ window .setTopLevelPosition (x , y );
625+ }
626+ });
653627 }
654628
655629
656- public void setSize (int width , int height ) {
630+ public void setSize (final int width , final int height ) {
657631 if (width == sketch .width && height == sketch .height ) {
658632 return ;
659633 }
@@ -669,7 +643,12 @@ public void setSize(int width, int height) {
669643 sketchWidth = width ;
670644 sketchHeight = height ;
671645 graphics .setSize (width , height );
672- window .setSize (width , height );
646+ display .getEDTUtil ().invoke (false , new Runnable () {
647+ @ Override
648+ public void run () {
649+ window .setSize (width , height );
650+ }
651+ });
673652 }
674653
675654
@@ -728,6 +707,12 @@ public void requestFocus() {
728707
729708 class DrawListener implements GLEventListener {
730709 public void display (GLAutoDrawable drawable ) {
710+ if (display .getEDTUtil ().isCurrentThreadEDT ()) {
711+ // For some reason, the first two frames of the animator are run on the
712+ // EDT, skipping rendering Processing's frame in that case.
713+ return ;
714+ }
715+
731716 pgl .getGL (drawable );
732717 int pframeCount = sketch .frameCount ;
733718 sketch .handleDraw ();
@@ -1137,21 +1122,32 @@ public void setCursor(PImage image, int hotspotX, int hotspotY) {
11371122 PixelFormat format = PixelFormat .ARGB8888 ;
11381123 final Dimension size = new Dimension (bimg .getWidth (), bimg .getHeight ());
11391124 PixelRectangle pixelrect = new PixelRectangle .GenericPixelRect (format , size , 0 , false , pixels );
1140- PointerIcon pi = disp .createPointerIcon (pixelrect , hotspotX , hotspotY );
1141- window .setPointerIcon (pi );
1125+ final PointerIcon pi = disp .createPointerIcon (pixelrect , hotspotX , hotspotY );
1126+ display .getEDTUtil ().invoke (false , new Runnable () {
1127+ @ Override
1128+ public void run () {
1129+ window .setPointerIcon (pi );
1130+ }
1131+ });
11421132 }
11431133
11441134
11451135 public void showCursor () {
1146- if (window != null ) {
1147- window .setPointerVisible (true );
1148- }
1136+ display .getEDTUtil ().invoke (false , new Runnable () {
1137+ @ Override
1138+ public void run () {
1139+ window .setPointerVisible (true );
1140+ }
1141+ });
11491142 }
11501143
11511144
11521145 public void hideCursor () {
1153- if (window != null ) {
1154- window .setPointerVisible (false );
1155- }
1146+ display .getEDTUtil ().invoke (false , new Runnable () {
1147+ @ Override
1148+ public void run () {
1149+ window .setPointerVisible (false );
1150+ }
1151+ });
11561152 }
11571153}
0 commit comments