From 547b2555d78c1bb77e3fb5a123457883f8ca77a2 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 22 Mar 2017 11:46:41 +0100 Subject: [PATCH] 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 --- app/src/processing/app/Base.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 18d988e8222..ab6781fb351 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -1433,7 +1433,7 @@ public void rebuildRecentBoardsMenu() throws Exception { boardMenuScroller.setTopFixedCount(3 + index); } - public void onBoardOrPortChange() { + public synchronized void onBoardOrPortChange() { BaseNoGui.onBoardOrPortChange(); // reload keywords when package/platform changes @@ -1643,7 +1643,20 @@ private JRadioButtonMenuItem createBoardMenusAndCustomMenus( @SuppressWarnings("serial") Action action = new AbstractAction(board.getName()) { public void actionPerformed(ActionEvent actionevent) { - selectTargetBoard((TargetBoard) getValue("b")); + new Thread() + { + public void run() { + if (activeEditor != null && activeEditor.isUploading()) { + // block until isUploading becomes false, but aboid blocking the UI + while (activeEditor.isUploading()) { + try { + Thread.sleep(100); + } catch (InterruptedException e) {} + } + } + selectTargetBoard((TargetBoard) getValue("b")); + } + }.start(); } }; action.putValue("b", board);