Skip to content

Commit 3babb54

Browse files
authored
Merge pull request processing#5141 from JakubValtar/fix-display-arg
Fix "Could not parse -1 for --dsiplay" error
2 parents ac1dd74 + 40cf90f commit 3babb54

1 file changed

Lines changed: 18 additions & 18 deletions

File tree

java/src/processing/mode/java/runner/Runner.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -400,26 +400,26 @@ protected StringList getSketchParams(boolean present, String[] args) {
400400

401401
// Make sure the display set in Preferences actually exists
402402
GraphicsDevice runDevice = editorDevice;
403-
if (runDisplay > 0) {
404-
if (runDisplay <= devices.length) {
403+
if (runDisplay > 0 && runDisplay <= devices.length) {
405404
runDevice = devices[runDisplay-1];
406-
407-
} else {
408-
// If a bad display is selected, use the same display as the editor
409-
if (runDisplay > 0) { // don't complain about -1 or 0
410-
System.err.println("Display " + runDisplay + " not available.");
411-
}
412-
runDevice = editorDevice;
413-
for (int i = 0; i < devices.length; i++) {
414-
if (devices[i] == runDevice) {
415-
// Wasn't setting the pref to avoid screwing things up with
416-
// something temporary. But not setting it makes debugging one's
417-
// setup just too damn weird, so changing that behavior.
418-
runDisplay = i + 1;
419-
System.err.println("Setting 'Run Sketches on Display' preference to display " + runDisplay);
420-
Preferences.setInteger("run.display", runDisplay);
421-
break;
405+
} else {
406+
// If a bad display (or -1 display) is selected, use the same display as the editor
407+
if (runDisplay > 0) { // don't complain about -1 or 0
408+
System.err.println("Display " + runDisplay + " not available.");
409+
}
410+
runDevice = editorDevice;
411+
for (int i = 0; i < devices.length; i++) {
412+
if (devices[i] == runDevice) {
413+
// Prevent message on the first run
414+
if (runDisplay != -1) {
415+
System.err.println("Setting 'Run Sketches on Display' preference to display " + (i+1));
422416
}
417+
runDisplay = i + 1;
418+
// Wasn't setting the pref to avoid screwing things up with
419+
// something temporary. But not setting it makes debugging one's
420+
// setup just too damn weird, so changing that behavior.
421+
Preferences.setInteger("run.display", runDisplay);
422+
break;
423423
}
424424
}
425425
}

0 commit comments

Comments
 (0)