Skip to content

Commit 9da24d1

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 arduino#6035
1 parent 804d890 commit 9da24d1

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
@@ -1291,7 +1291,7 @@ public void rebuildExamplesMenu(JMenu menu) {
12911291
private static String priorPlatformFolder;
12921292
private static boolean newLibraryImported;
12931293

1294-
public void onBoardOrPortChange() {
1294+
public synchronized void onBoardOrPortChange() {
12951295
BaseNoGui.onBoardOrPortChange();
12961296

12971297
// reload keywords when package/platform changes
@@ -1490,12 +1490,26 @@ private JRadioButtonMenuItem createBoardMenusAndCustomMenus(
14901490
@SuppressWarnings("serial")
14911491
Action action = new AbstractAction(board.getName()) {
14921492
public void actionPerformed(ActionEvent actionevent) {
1493-
BaseNoGui.selectBoard((TargetBoard) getValue("b"));
1494-
filterVisibilityOfSubsequentBoardMenus(boardsCustomMenus, (TargetBoard) getValue("b"), 1);
14951493

1496-
onBoardOrPortChange();
1497-
rebuildImportMenu(Editor.importMenu);
1498-
rebuildExamplesMenu(Editor.examplesMenu);
1494+
new Thread()
1495+
{
1496+
public void run() {
1497+
if (activeEditor != null && activeEditor.isCompiling()) {
1498+
// block until isCompiling becomes false, but aboid blocking the UI
1499+
while (activeEditor.isCompiling()) {
1500+
try {
1501+
Thread.sleep(100);
1502+
} catch (InterruptedException e) {}
1503+
}
1504+
}
1505+
1506+
BaseNoGui.selectBoard((TargetBoard) getValue("b"));
1507+
filterVisibilityOfSubsequentBoardMenus(boardsCustomMenus, (TargetBoard) getValue("b"), 1);
1508+
onBoardOrPortChange();
1509+
rebuildImportMenu(Editor.importMenu);
1510+
rebuildExamplesMenu(Editor.examplesMenu);
1511+
}
1512+
}.start();
14991513
}
15001514
};
15011515
action.putValue("b", board);

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

+4
Original file line numberDiff line numberDiff line change
@@ -2166,6 +2166,10 @@ public void run() {
21662166
}
21672167
}
21682168

2169+
public boolean isCompiling() {
2170+
return uploading;
2171+
}
2172+
21692173
private void resumeOrCloseSerialMonitor() {
21702174
// Return the serial monitor window to its initial state
21712175
if (serialMonitor != null) {

0 commit comments

Comments
 (0)