ensure game loop won't crash if broodwar isn't running when interrupted
This commit is contained in:
parent
564133f95a
commit
38ab003dca
|
@ -145,11 +145,6 @@ public class Mirror {
|
||||||
System.out.println(LOG_TAG + "Match already running.");
|
System.out.println(LOG_TAG + "Match already running.");
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (Thread.interrupted()) {
|
|
||||||
System.out.println(LOG_TAG + "Interrupted.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!inGame) {
|
if (!inGame) {
|
||||||
if (previouslyInGame) {
|
if (previouslyInGame) {
|
||||||
System.out.println(LOG_TAG + "Match ended.");
|
System.out.println(LOG_TAG + "Match ended.");
|
||||||
|
@ -172,6 +167,11 @@ public class Mirror {
|
||||||
reconnect();
|
reconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Thread.interrupted()) {
|
||||||
|
System.out.println(LOG_TAG + "Interrupted.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
previouslyInGame = inGame;
|
previouslyInGame = inGame;
|
||||||
inGame = game.isInGame();
|
inGame = game.isInGame();
|
||||||
}
|
}
|
||||||
|
@ -192,6 +192,9 @@ public class Mirror {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (InterruptedException e) {
|
} 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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue