Skip to content

Commit f975068

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 d191610 commit f975068

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

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

+15-2
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,7 @@ public void rebuildRecentBoardsMenu() throws Exception {
14221422
boardMenuScroller.setTopFixedCount(3 + index);
14231423
}
14241424

1425-
public void onBoardOrPortChange() {
1425+
public synchronized void onBoardOrPortChange() {
14261426
BaseNoGui.onBoardOrPortChange();
14271427

14281428
// reload keywords when package/platform changes
@@ -1632,7 +1632,20 @@ private JRadioButtonMenuItem createBoardMenusAndCustomMenus(
16321632
@SuppressWarnings("serial")
16331633
Action action = new AbstractAction(board.getName()) {
16341634
public void actionPerformed(ActionEvent actionevent) {
1635-
selectTargetBoard((TargetBoard) getValue("b"));
1635+
new Thread()
1636+
{
1637+
public void run() {
1638+
if (activeEditor != null && activeEditor.isCompiling()) {
1639+
// block until isCompiling becomes false, but aboid blocking the UI
1640+
while (activeEditor.isCompiling()) {
1641+
try {
1642+
Thread.sleep(100);
1643+
} catch (InterruptedException e) {}
1644+
}
1645+
}
1646+
selectTargetBoard((TargetBoard) getValue("b"));
1647+
}
1648+
}.start();
16361649
}
16371650
};
16381651
action.putValue("b", board);

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

+4
Original file line numberDiff line numberDiff line change
@@ -2151,6 +2151,10 @@ public void run() {
21512151
}
21522152
}
21532153

2154+
public boolean isCompiling() {
2155+
return uploading;
2156+
}
2157+
21542158
private void resumeOrCloseSerialMonitor() {
21552159
// Return the serial monitor window to its initial state
21562160
if (serialMonitor != null) {

0 commit comments

Comments
 (0)