Skip to content

Commit f36e422

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 7e7251d commit f36e422

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
@@ -1398,7 +1398,7 @@ public void rebuildRecentBoardsMenu() throws Exception {
13981398
boardMenuScroller.setTopFixedCount(3 + index);
13991399
}
14001400

1401-
public void onBoardOrPortChange() {
1401+
public synchronized void onBoardOrPortChange() {
14021402
BaseNoGui.onBoardOrPortChange();
14031403

14041404
// reload keywords when package/platform changes
@@ -1605,7 +1605,20 @@ private JRadioButtonMenuItem createBoardMenusAndCustomMenus(
16051605
@SuppressWarnings("serial")
16061606
Action action = new AbstractAction(board.getName()) {
16071607
public void actionPerformed(ActionEvent actionevent) {
1608-
selectTargetBoard((TargetBoard) getValue("b"));
1608+
new Thread()
1609+
{
1610+
public void run() {
1611+
if (activeEditor != null && activeEditor.isCompiling()) {
1612+
// block until isCompiling becomes false, but aboid blocking the UI
1613+
while (activeEditor.isCompiling()) {
1614+
try {
1615+
Thread.sleep(100);
1616+
} catch (InterruptedException e) {}
1617+
}
1618+
}
1619+
selectTargetBoard((TargetBoard) getValue("b"));
1620+
}
1621+
}.start();
16091622
}
16101623
};
16111624
action.putValue("b", board);

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

+4
Original file line numberDiff line numberDiff line change
@@ -2146,6 +2146,10 @@ public void run() {
21462146
}
21472147
}
21482148

2149+
public boolean isCompiling() {
2150+
return uploading;
2151+
}
2152+
21492153
private void resumeOrCloseSerialMonitor() {
21502154
// Return the serial monitor window to its initial state
21512155
if (serialMonitor != null) {

0 commit comments

Comments
 (0)