Skip to content

Commit f78bf8d

Browse files
facchinmcmaglie
authored andcommitted
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 7af80fc commit f78bf8d

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
@@ -1306,7 +1306,7 @@ public void rebuildExamplesMenu(JMenu menu) {
13061306
private static String priorPlatformFolder;
13071307
private static boolean newLibraryImported;
13081308

1309-
public void onBoardOrPortChange() {
1309+
public synchronized void onBoardOrPortChange() {
13101310
BaseNoGui.onBoardOrPortChange();
13111311

13121312
// reload keywords when package/platform changes
@@ -1505,12 +1505,26 @@ private JRadioButtonMenuItem createBoardMenusAndCustomMenus(
15051505
@SuppressWarnings("serial")
15061506
Action action = new AbstractAction(board.getName()) {
15071507
public void actionPerformed(ActionEvent actionevent) {
1508-
BaseNoGui.selectBoard((TargetBoard) getValue("b"));
1509-
filterVisibilityOfSubsequentBoardMenus(boardsCustomMenus, (TargetBoard) getValue("b"), 1);
15101508

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

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

+4
Original file line numberDiff line numberDiff line change
@@ -2265,6 +2265,10 @@ public void run() {
22652265
}
22662266
}
22672267

2268+
public boolean isCompiling() {
2269+
return uploading;
2270+
}
2271+
22682272
private void resumeOrCloseSerialMonitor() {
22692273
// Return the serial monitor window to its initial state
22702274
if (serialMonitor != null) {

0 commit comments

Comments
 (0)