diff --git a/src/main/java/featurecat/lizzie/rules/Board.java b/src/main/java/featurecat/lizzie/rules/Board.java index 18499562..d1efc7f5 100644 --- a/src/main/java/featurecat/lizzie/rules/Board.java +++ b/src/main/java/featurecat/lizzie/rules/Board.java @@ -7,6 +7,7 @@ import featurecat.lizzie.analysis.Leelaz; import featurecat.lizzie.analysis.LeelazListener; import featurecat.lizzie.analysis.MoveData; +import featurecat.lizzie.util.Utils; import java.io.IOException; import java.util.ArrayDeque; import java.util.ArrayList; @@ -22,6 +23,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import javax.swing.JOptionPane; +import javax.swing.SwingUtilities; import org.json.JSONException; public class Board implements LeelazListener { @@ -1476,6 +1478,11 @@ public void toggleAnalysis() { } public void bestMoveNotification(List bestMoves) { + SwingUtilities.invokeLater(() -> bestMoveNotificationInEDT(bestMoves)); + } + + private void bestMoveNotificationInEDT(List bestMoves) { + Utils.mustBeEventDispatchThread(); if (analysisMode) { boolean isSuccessivePass = (history.getPrevious().isPresent() @@ -1496,6 +1503,10 @@ public void bestMoveNotification(List bestMoves) { sum += move.playouts; } if (sum >= playoutsAnalysis) { + // We need to call this "nextMove()" in EDT. + // Otherwise, it can flip history.isBlacksTurn() BEFORE + // drawEstimateRectKataInEDT(). + // Then the ownerships are drawn with wrong colors. nextMove(); } }