Skip to content

Commit

Permalink
RunMode: prevent controllerDisconnected() getting called multiple tim…
Browse files Browse the repository at this point in the history
…es if stopper thread is not executed immediately
  • Loading branch information
bwRavencl committed Oct 19, 2023
1 parent 256e435 commit 8ff9d65
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public abstract class RunMode implements Runnable {
int minAxisValue;
int maxAxisValue;
int nButtons;
private boolean stopping;

RunMode(final Main main, final Input input) {
this.main = main;
Expand All @@ -42,6 +43,10 @@ public abstract class RunMode implements Runnable {
}

final void controllerDisconnected() {
if (stopping) {
return;
}

Thread.startVirtualThread(() -> main.stopAll(true, true, true));

log.log(Level.WARNING, Main.assembleControllerLoggingMessage("Could not read from", input.getController()));
Expand All @@ -50,6 +55,8 @@ final void controllerDisconnected() {
Main.strings.getString("COULD_NOT_READ_FROM_CONTROLLER_DIALOG_TEXT"),
Main.strings.getString("ERROR_DIALOG_TITLE"),
JOptionPane.ERROR_MESSAGE));

stopping = true;
}

abstract Logger getLogger();
Expand Down

0 comments on commit 8ff9d65

Please sign in to comment.