Skip to content

Commit f66d666

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 32c7271 commit f66d666

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
@@ -1309,7 +1309,7 @@ public void rebuildExamplesMenu(JMenu menu) {
13091309
private static String priorPlatformFolder;
13101310
private static boolean newLibraryImported;
13111311

1312-
public void onBoardOrPortChange() {
1312+
public synchronized void onBoardOrPortChange() {
13131313
BaseNoGui.onBoardOrPortChange();
13141314

13151315
// reload keywords when package/platform changes
@@ -1508,12 +1508,26 @@ private JRadioButtonMenuItem createBoardMenusAndCustomMenus(
15081508
@SuppressWarnings("serial")
15091509
Action action = new AbstractAction(board.getName()) {
15101510
public void actionPerformed(ActionEvent actionevent) {
1511-
BaseNoGui.selectBoard((TargetBoard) getValue("b"));
1512-
filterVisibilityOfSubsequentBoardMenus(boardsCustomMenus, (TargetBoard) getValue("b"), 1);
15131511

1514-
onBoardOrPortChange();
1515-
rebuildImportMenu(Editor.importMenu);
1516-
rebuildExamplesMenu(Editor.examplesMenu);
1512+
new Thread()
1513+
{
1514+
public void run() {
1515+
if (activeEditor != null && activeEditor.isCompiling()) {
1516+
// block until isCompiling becomes false, but aboid blocking the UI
1517+
while (activeEditor.isCompiling()) {
1518+
try {
1519+
Thread.sleep(100);
1520+
} catch (InterruptedException e) {}
1521+
}
1522+
}
1523+
1524+
BaseNoGui.selectBoard((TargetBoard) getValue("b"));
1525+
filterVisibilityOfSubsequentBoardMenus(boardsCustomMenus, (TargetBoard) getValue("b"), 1);
1526+
onBoardOrPortChange();
1527+
rebuildImportMenu(Editor.importMenu);
1528+
rebuildExamplesMenu(Editor.examplesMenu);
1529+
}
1530+
}.start();
15171531
}
15181532
};
15191533
action.putValue("b", board);

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

+4
Original file line numberDiff line numberDiff line change
@@ -2271,6 +2271,10 @@ public void run() {
22712271
}
22722272
}
22732273

2274+
public boolean isCompiling() {
2275+
return uploading;
2276+
}
2277+
22742278
private void resumeOrCloseSerialMonitor() {
22752279
// Return the serial monitor window to its initial state
22762280
if (serialMonitor != null) {

0 commit comments

Comments
 (0)