@@ -85,16 +85,24 @@ public class Runner implements MessageConsumer {
8585
8686 public Runner (JavaBuild build , RunnerListener listener ) throws SketchException {
8787 this .listener = listener ;
88- // this.sketch = sketch;
8988 this .build = build ;
9089
9190 checkLocalHost ();
9291
93- if (listener instanceof JavaEditor ) {
94- this .editor = (JavaEditor ) listener ;
95- sketchErr = editor .getConsole ().getErr ();
96- sketchOut = editor .getConsole ().getOut ();
97- } else {
92+ if (listener instanceof RunnerListenerEdtAdapter ) {
93+ // RunnerListener gets wrapped so that it behaves on the EDT.
94+ // Need to extract the wrapped Object and see if it's a Java Editor,
95+ // in which case we'll be passing additional parameters to the PApplet.
96+ // https://github.com/processing/processing/issues/5843
97+ RunnerListener wrapped = ((RunnerListenerEdtAdapter ) listener ).getWrapped ();
98+ if (wrapped instanceof JavaEditor ) {
99+ editor = (JavaEditor ) wrapped ;
100+ sketchErr = editor .getConsole ().getErr ();
101+ sketchOut = editor .getConsole ().getOut ();
102+ }
103+ }
104+ // If it's not a JavaEditor, then we don't redirect to a console.
105+ if (editor == null ) {
98106 sketchErr = System .err ;
99107 sketchOut = System .out ;
100108 }
@@ -466,10 +474,8 @@ protected StringList getSketchParams(boolean present, String[] args) {
466474 }
467475 params .append (PApplet .ARGS_EXTERNAL );
468476 }
469-
470477 params .append (PApplet .ARGS_DISPLAY + "=" + runDisplay );
471478
472-
473479 if (present ) {
474480 params .append (PApplet .ARGS_PRESENT );
475481// if (Preferences.getBoolean("run.present.exclusive")) {
@@ -495,6 +501,7 @@ protected StringList getSketchParams(boolean present, String[] args) {
495501 if (args != null ) {
496502 params .append (args );
497503 }
504+
498505 // Pass back the whole list
499506 return params ;
500507 }
0 commit comments