diff --git a/gui/src/controller/Controller.java b/gui/src/controller/Controller.java index 42bba4d8a1250fd4830b9faa051c03cf01903fb6..501b215a10e783f64131d14a1b8e8c6ea73465d2 100644 --- a/gui/src/controller/Controller.java +++ b/gui/src/controller/Controller.java @@ -50,6 +50,13 @@ public class Controller implements Initializable { this.gameProcess = new ProcessBuilder("../bin/theturk").start(); gameInput = new PrintWriter(new OutputStreamWriter(gameProcess.getOutputStream()), true); + Runtime.getRuntime().addShutdownHook(new Thread() + { + public void run() + { + gameProcess.destroy(); + } + }); } catch (IOException e) { diff --git a/gui/src/controller/UpdateThread.java b/gui/src/controller/UpdateThread.java index 0d70aa388b25b5feb5e42255581ba4c9197f4bec..fb2d51782bfa7cc9a6e388675c3054dff04a5ad6 100644 --- a/gui/src/controller/UpdateThread.java +++ b/gui/src/controller/UpdateThread.java @@ -26,7 +26,7 @@ public class UpdateThread extends Thread this.board = board; this.boardView = boardView; } - + public void run() { @@ -69,10 +69,19 @@ public class UpdateThread extends Thread Alert alert = new Alert(Alert.AlertType.ERROR, "Error during reading from penguin program!", ButtonType.FINISH); alert.showAndWait(); e.printStackTrace(); - System.exit(1); + Platform.exit(); + }); + } + catch (Throwable e) + { + gameRunning = false; + Platform.runLater(() -> { + Alert alert = new Alert(Alert.AlertType.ERROR, "Unhandled exception in update thread: " + e.getMessage(), ButtonType.FINISH); + alert.showAndWait(); + e.printStackTrace(); + Platform.exit(); }); } - } } }