Skip to content

Commit fa51a39

Browse files
committed
Fix SerialMonitor and SerialPlotter lifecycles
Fixes #7683 When the selected serial port is busy both monitors now avoid displaying a useless window, cleaning the status area once the open succeeds.
1 parent 0a84ac2 commit fa51a39

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Diff for: app/src/processing/app/Editor.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -2409,11 +2409,12 @@ public void handleSerial() {
24092409
}
24102410

24112411
try {
2412-
serialMonitor.setVisible(true);
24132412
if (!avoidMultipleOperations) {
24142413
serialMonitor.open();
24152414
}
2415+
serialMonitor.setVisible(true);
24162416
success = true;
2417+
statusEmpty();
24172418
} catch (ConnectException e) {
24182419
statusError(tr("Unable to connect: is the sketch using the bridge?"));
24192420
} catch (JSchException e) {
@@ -2423,6 +2424,7 @@ public void handleSerial() {
24232424
if (e.getCause() != null && e.getCause() instanceof SerialPortException) {
24242425
errorMessage += " (" + ((SerialPortException) e.getCause()).getExceptionType() + ")";
24252426
}
2427+
serialMonitor = null;
24262428
statusError(errorMessage);
24272429
try {
24282430
serialMonitor.close();
@@ -2432,12 +2434,12 @@ public void handleSerial() {
24322434
} catch (Exception e) {
24332435
statusError(e);
24342436
} finally {
2435-
if (serialMonitor.requiresAuthorization() && !success) {
2437+
if (serialMonitor != null && serialMonitor.requiresAuthorization() && !success) {
24362438
PreferencesData.remove(serialMonitor.getAuthorizationKey());
24372439
}
24382440
}
24392441

2440-
} while (serialMonitor.requiresAuthorization() && !success);
2442+
} while (serialMonitor != null && serialMonitor.requiresAuthorization() && !success);
24412443

24422444
}
24432445

@@ -2457,6 +2459,7 @@ public void handlePlotter() {
24572459
if (serialPlotter.isClosed()) {
24582460
// If it's closed, clear the refrence to the existing
24592461
// plotter and create a new one
2462+
serialPlotter.dispose();
24602463
serialPlotter = null;
24612464
}
24622465
else {
@@ -2510,6 +2513,7 @@ public void handlePlotter() {
25102513
serialPlotter.open();
25112514
serialPlotter.setVisible(true);
25122515
success = true;
2516+
statusEmpty();
25132517
} catch (ConnectException e) {
25142518
statusError(tr("Unable to connect: is the sketch using the bridge?"));
25152519
} catch (JSchException e) {
@@ -2520,15 +2524,16 @@ public void handlePlotter() {
25202524
errorMessage += " (" + ((SerialPortException) e.getCause()).getExceptionType() + ")";
25212525
}
25222526
statusError(errorMessage);
2527+
serialPlotter = null;
25232528
} catch (Exception e) {
25242529
statusError(e);
25252530
} finally {
2526-
if (serialPlotter.requiresAuthorization() && !success) {
2531+
if (serialPlotter != null && serialPlotter.requiresAuthorization() && !success) {
25272532
PreferencesData.remove(serialPlotter.getAuthorizationKey());
25282533
}
25292534
}
25302535

2531-
} while (serialPlotter.requiresAuthorization() && !success);
2536+
} while (serialPlotter != null && serialPlotter.requiresAuthorization() && !success);
25322537

25332538
}
25342539

0 commit comments

Comments
 (0)