Skip to content

Commit 547b255

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 1eba2d3 commit 547b255

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

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

+15-2
Original file line numberDiff line numberDiff line change
@@ -1433,7 +1433,7 @@ public void rebuildRecentBoardsMenu() throws Exception {
14331433
boardMenuScroller.setTopFixedCount(3 + index);
14341434
}
14351435

1436-
public void onBoardOrPortChange() {
1436+
public synchronized void onBoardOrPortChange() {
14371437
BaseNoGui.onBoardOrPortChange();
14381438

14391439
// reload keywords when package/platform changes
@@ -1643,7 +1643,20 @@ private JRadioButtonMenuItem createBoardMenusAndCustomMenus(
16431643
@SuppressWarnings("serial")
16441644
Action action = new AbstractAction(board.getName()) {
16451645
public void actionPerformed(ActionEvent actionevent) {
1646-
selectTargetBoard((TargetBoard) getValue("b"));
1646+
new Thread()
1647+
{
1648+
public void run() {
1649+
if (activeEditor != null && activeEditor.isUploading()) {
1650+
// block until isUploading becomes false, but aboid blocking the UI
1651+
while (activeEditor.isUploading()) {
1652+
try {
1653+
Thread.sleep(100);
1654+
} catch (InterruptedException e) {}
1655+
}
1656+
}
1657+
selectTargetBoard((TargetBoard) getValue("b"));
1658+
}
1659+
}.start();
16471660
}
16481661
};
16491662
action.putValue("b", board);

0 commit comments

Comments
 (0)