From 25489f1c2f78654bd0814022394ebeae209be14c 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 b89a5eeaeb2..670fc17b92d 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -1422,7 +1422,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 @@ -1632,7 +1632,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);