Skip to content

Commit 559eca8

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 4b0a330 commit 559eca8

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

1313-
public void onBoardOrPortChange() {
1313+
public synchronized void onBoardOrPortChange() {
13141314
BaseNoGui.onBoardOrPortChange();
13151315

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

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

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

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

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

0 commit comments

Comments
 (0)