Skip to content

Commit e099b9f

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 22fe051 commit e099b9f

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
@@ -1313,7 +1313,7 @@ public void rebuildExamplesMenu(JMenu menu) {
13131313
private static String priorPlatformFolder;
13141314
private static boolean newLibraryImported;
13151315

1316-
public void onBoardOrPortChange() {
1316+
public synchronized void onBoardOrPortChange() {
13171317
BaseNoGui.onBoardOrPortChange();
13181318

13191319
// reload keywords when package/platform changes
@@ -1512,12 +1512,26 @@ private JRadioButtonMenuItem createBoardMenusAndCustomMenus(
15121512
@SuppressWarnings("serial")
15131513
Action action = new AbstractAction(board.getName()) {
15141514
public void actionPerformed(ActionEvent actionevent) {
1515-
BaseNoGui.selectBoard((TargetBoard) getValue("b"));
1516-
filterVisibilityOfSubsequentBoardMenus(boardsCustomMenus, (TargetBoard) getValue("b"), 1);
15171515

1518-
onBoardOrPortChange();
1519-
rebuildImportMenu(Editor.importMenu);
1520-
rebuildExamplesMenu(Editor.examplesMenu);
1516+
new Thread()
1517+
{
1518+
public void run() {
1519+
if (activeEditor != null && activeEditor.isCompiling()) {
1520+
// block until isCompiling becomes false, but aboid blocking the UI
1521+
while (activeEditor.isCompiling()) {
1522+
try {
1523+
Thread.sleep(100);
1524+
} catch (InterruptedException e) {}
1525+
}
1526+
}
1527+
1528+
BaseNoGui.selectBoard((TargetBoard) getValue("b"));
1529+
filterVisibilityOfSubsequentBoardMenus(boardsCustomMenus, (TargetBoard) getValue("b"), 1);
1530+
onBoardOrPortChange();
1531+
rebuildImportMenu(Editor.importMenu);
1532+
rebuildExamplesMenu(Editor.examplesMenu);
1533+
}
1534+
}.start();
15211535
}
15221536
};
15231537
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)