From 38ab003dca8d02ff5419431ad90430798bb8fabf Mon Sep 17 00:00:00 2001 From: gered Date: Fri, 14 Apr 2017 18:43:19 -0400 Subject: [PATCH] ensure game loop won't crash if broodwar isn't running when interrupted --- manual-bwapi-src/Mirror.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/manual-bwapi-src/Mirror.java b/manual-bwapi-src/Mirror.java index effb78b..da730e5 100644 --- a/manual-bwapi-src/Mirror.java +++ b/manual-bwapi-src/Mirror.java @@ -145,11 +145,6 @@ public class Mirror { System.out.println(LOG_TAG + "Match already running."); while (true) { - if (Thread.interrupted()) { - System.out.println(LOG_TAG + "Interrupted."); - break; - } - if (!inGame) { if (previouslyInGame) { System.out.println(LOG_TAG + "Match ended."); @@ -172,6 +167,11 @@ public class Mirror { reconnect(); } + if (Thread.interrupted()) { + System.out.println(LOG_TAG + "Interrupted."); + break; + } + previouslyInGame = inGame; inGame = game.isInGame(); } @@ -192,6 +192,9 @@ public class Mirror { try { Thread.sleep(1000); } catch (InterruptedException e) { + // needed to set the interrupt status of this thread. + // else, subsequent calls to Thread.interrupted() will return false. + Thread.currentThread().interrupt(); return false; } }