Skip to content

Commit 6f77329

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 7a15101 commit 6f77329

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
@@ -1328,7 +1328,7 @@ public void rebuildExamplesMenu(JMenu menu) {
13281328
private static String priorPlatformFolder;
13291329
private static boolean newLibraryImported;
13301330

1331-
public void onBoardOrPortChange() {
1331+
public synchronized void onBoardOrPortChange() {
13321332
BaseNoGui.onBoardOrPortChange();
13331333

13341334
// reload keywords when package/platform changes
@@ -1527,12 +1527,26 @@ private JRadioButtonMenuItem createBoardMenusAndCustomMenus(
15271527
@SuppressWarnings("serial")
15281528
Action action = new AbstractAction(board.getName()) {
15291529
public void actionPerformed(ActionEvent actionevent) {
1530-
BaseNoGui.selectBoard((TargetBoard) getValue("b"));
1531-
filterVisibilityOfSubsequentBoardMenus(boardsCustomMenus, (TargetBoard) getValue("b"), 1);
15321530

1533-
onBoardOrPortChange();
1534-
rebuildImportMenu(Editor.importMenu);
1535-
rebuildExamplesMenu(Editor.examplesMenu);
1531+
new Thread()
1532+
{
1533+
public void run() {
1534+
if (activeEditor != null && activeEditor.isCompiling()) {
1535+
// block until isCompiling becomes false, but aboid blocking the UI
1536+
while (activeEditor.isCompiling()) {
1537+
try {
1538+
Thread.sleep(100);
1539+
} catch (InterruptedException e) {}
1540+
}
1541+
}
1542+
1543+
BaseNoGui.selectBoard((TargetBoard) getValue("b"));
1544+
filterVisibilityOfSubsequentBoardMenus(boardsCustomMenus, (TargetBoard) getValue("b"), 1);
1545+
onBoardOrPortChange();
1546+
rebuildImportMenu(Editor.importMenu);
1547+
rebuildExamplesMenu(Editor.examplesMenu);
1548+
}
1549+
}.start();
15361550
}
15371551
};
15381552
action.putValue("b", board);

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

+4
Original file line numberDiff line numberDiff line change
@@ -2110,6 +2110,10 @@ public void run() {
21102110
}
21112111
}
21122112

2113+
public boolean isCompiling() {
2114+
return uploading;
2115+
}
2116+
21132117
private void resumeOrCloseSerialMonitor() {
21142118
// Return the serial monitor window to its initial state
21152119
if (serialMonitor != null) {

0 commit comments

Comments
 (0)