Skip to content

Commit 931b1d0

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 f6b752b commit 931b1d0

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
@@ -1308,7 +1308,7 @@ public void rebuildExamplesMenu(JMenu menu) {
13081308
private static String priorPlatformFolder;
13091309
private static boolean newLibraryImported;
13101310

1311-
public void onBoardOrPortChange() {
1311+
public synchronized void onBoardOrPortChange() {
13121312
BaseNoGui.onBoardOrPortChange();
13131313

13141314
// reload keywords when package/platform changes
@@ -1507,12 +1507,26 @@ private JRadioButtonMenuItem createBoardMenusAndCustomMenus(
15071507
@SuppressWarnings("serial")
15081508
Action action = new AbstractAction(board.getName()) {
15091509
public void actionPerformed(ActionEvent actionevent) {
1510-
BaseNoGui.selectBoard((TargetBoard) getValue("b"));
1511-
filterVisibilityOfSubsequentBoardMenus(boardsCustomMenus, (TargetBoard) getValue("b"), 1);
15121510

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

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

+4
Original file line numberDiff line numberDiff line change
@@ -2118,6 +2118,10 @@ public void run() {
21182118
}
21192119
}
21202120

2121+
public boolean isCompiling() {
2122+
return uploading;
2123+
}
2124+
21212125
private void resumeOrCloseSerialMonitor() {
21222126
// Return the serial monitor window to its initial state
21232127
if (serialMonitor != null) {

0 commit comments

Comments
 (0)