Skip to content

Commit 91f11a5

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 8e515a2 commit 91f11a5

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

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);

app/src/processing/app/Editor.java

+4
Original file line numberDiff line numberDiff line change
@@ -2228,6 +2228,10 @@ public void run() {
22282228
}
22292229
}
22302230

2231+
public boolean isCompiling() {
2232+
return uploading;
2233+
}
2234+
22312235
private void resumeOrCloseSerialMonitor() {
22322236
// Return the serial monitor window to its initial state
22332237
if (serialMonitor != null) {

0 commit comments

Comments
 (0)