Skip to content

Commit

Permalink
Avoid board change during compilation/upload
Browse files Browse the repository at this point in the history
By threading the boardChange callback we can busy wait until
the compilation/upload phase has ended and change the board when done.

Fixes #6035
  • Loading branch information
facchinm committed Jan 19, 2019
1 parent 6ae1998 commit 5f3aa1f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
26 changes: 20 additions & 6 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,7 @@ public void rebuildExamplesMenu(JMenu menu) {
private static String priorPlatformFolder;
private static boolean newLibraryImported;

public void onBoardOrPortChange() {
public synchronized void onBoardOrPortChange() {
BaseNoGui.onBoardOrPortChange();

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

onBoardOrPortChange();
rebuildImportMenu(Editor.importMenu);
rebuildExamplesMenu(Editor.examplesMenu);
new Thread()
{
public void run() {
if (activeEditor != null && activeEditor.isCompiling()) {
// block until isCompiling becomes false, but aboid blocking the UI
while (activeEditor.isCompiling()) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {}
}
}

BaseNoGui.selectBoard((TargetBoard) getValue("b"));
filterVisibilityOfSubsequentBoardMenus(boardsCustomMenus, (TargetBoard) getValue("b"), 1);
onBoardOrPortChange();
rebuildImportMenu(Editor.importMenu);
rebuildExamplesMenu(Editor.examplesMenu);
}
}.start();
}
};
action.putValue("b", board);
Expand Down
4 changes: 4 additions & 0 deletions app/src/processing/app/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2118,6 +2118,10 @@ public void run() {
}
}

public boolean isCompiling() {
return uploading;
}

private void resumeOrCloseSerialMonitor() {
// Return the serial monitor window to its initial state
if (serialMonitor != null) {
Expand Down

0 comments on commit 5f3aa1f

Please sign in to comment.