Skip to content

Commit eaa705c

Browse files
committed
Avoid board change during compilation/upload
By threading the boardChange callback we can busy wait until the compilation/upload phase has ended and change the board when done. Fixes #6035
1 parent ef48828 commit eaa705c

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

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

+20-6
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,7 @@ public void rebuildExamplesMenu(JMenu menu) {
13111311
private static String priorPlatformFolder;
13121312
private static boolean newLibraryImported;
13131313

1314-
public void onBoardOrPortChange() {
1314+
public synchronized void onBoardOrPortChange() {
13151315
BaseNoGui.onBoardOrPortChange();
13161316

13171317
// reload keywords when package/platform changes
@@ -1510,12 +1510,26 @@ private JRadioButtonMenuItem createBoardMenusAndCustomMenus(
15101510
@SuppressWarnings("serial")
15111511
Action action = new AbstractAction(board.getName()) {
15121512
public void actionPerformed(ActionEvent actionevent) {
1513-
BaseNoGui.selectBoard((TargetBoard) getValue("b"));
1514-
filterVisibilityOfSubsequentBoardMenus(boardsCustomMenus, (TargetBoard) getValue("b"), 1);
15151513

1516-
onBoardOrPortChange();
1517-
rebuildImportMenu(Editor.importMenu);
1518-
rebuildExamplesMenu(Editor.examplesMenu);
1514+
new Thread()
1515+
{
1516+
public void run() {
1517+
if (activeEditor != null && activeEditor.isCompiling()) {
1518+
// block until isCompiling becomes false, but aboid blocking the UI
1519+
while (activeEditor.isCompiling()) {
1520+
try {
1521+
Thread.sleep(100);
1522+
} catch (InterruptedException e) {}
1523+
}
1524+
}
1525+
1526+
BaseNoGui.selectBoard((TargetBoard) getValue("b"));
1527+
filterVisibilityOfSubsequentBoardMenus(boardsCustomMenus, (TargetBoard) getValue("b"), 1);
1528+
onBoardOrPortChange();
1529+
rebuildImportMenu(Editor.importMenu);
1530+
rebuildExamplesMenu(Editor.examplesMenu);
1531+
}
1532+
}.start();
15191533
}
15201534
};
15211535
action.putValue("b", board);

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

+4
Original file line numberDiff line numberDiff line change
@@ -2266,6 +2266,10 @@ public void run() {
22662266
}
22672267
}
22682268

2269+
public boolean isCompiling() {
2270+
return uploading;
2271+
}
2272+
22692273
private void resumeOrCloseSerialMonitor() {
22702274
// Return the serial monitor window to its initial state
22712275
if (serialMonitor != null) {

0 commit comments

Comments
 (0)