From 8ff9d651e9e000f23296f9dfd4114797f441e132 Mon Sep 17 00:00:00 2001 From: Matteo Hausner Date: Fri, 20 Oct 2023 00:13:31 +0200 Subject: [PATCH] RunMode: prevent controllerDisconnected() getting called multiple times if stopper thread is not executed immediately --- .../java/de/bwravencl/controllerbuddy/runmode/RunMode.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/de/bwravencl/controllerbuddy/runmode/RunMode.java b/src/main/java/de/bwravencl/controllerbuddy/runmode/RunMode.java index 07e64ec7..f4bc8f95 100644 --- a/src/main/java/de/bwravencl/controllerbuddy/runmode/RunMode.java +++ b/src/main/java/de/bwravencl/controllerbuddy/runmode/RunMode.java @@ -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; @@ -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())); @@ -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();