From 466e22437bbd4bffc386853f08a7ce01fb75b301 Mon Sep 17 00:00:00 2001 From: fjc40 Date: Sun, 7 May 2017 18:34:44 +1200 Subject: [PATCH] Visualiser. The nullptr issues relating to the XML data files appears to be fixed. Essentially, the StartController.startRaceNoScaling() function was being called as soon possible, before it was even ready - setRaceClock either hadn't been called or hadn't finished executing yet, so the StartController.raceClock member was null, causing crashes. Also changed the while(visualiserInput.getRaceStatus() == null) loops to an if-then-return early block. They caused the program to freeze if the race data source wasn't sending any race status messages (currently, our mock doesn't send any once the race has finished). #story[782] --- mock/src/main/java/seng302/MockOutput.java | 1 + .../seng302/Controllers/StartController.java | 38 +++++++++++++++---- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/mock/src/main/java/seng302/MockOutput.java b/mock/src/main/java/seng302/MockOutput.java index d48bd488..728b29a6 100644 --- a/mock/src/main/java/seng302/MockOutput.java +++ b/mock/src/main/java/seng302/MockOutput.java @@ -162,6 +162,7 @@ public class MockOutput implements Runnable try { while (true){ + System.out.println("Waiting for a connection...");//TEMP DEBUG REMOVE mockSocket = serverSocket.accept(); outToVisualiser = new DataOutputStream(mockSocket.getOutputStream()); diff --git a/visualiser/src/main/java/seng302/Controllers/StartController.java b/visualiser/src/main/java/seng302/Controllers/StartController.java index b4a9e511..cf660860 100644 --- a/visualiser/src/main/java/seng302/Controllers/StartController.java +++ b/visualiser/src/main/java/seng302/Controllers/StartController.java @@ -55,12 +55,16 @@ public class StartController extends Controller implements Observer { private VisualiserInput visualiserInput; + ///Tracks whether the race has been started (that is, has startRaceNoScaling() be called). + boolean hasRaceStarted = false; + /** * Begins the race with a scale factor of 1 */ public void startRaceNoScaling() { //startRace(1); - while(visualiserInput.getRaceStatus() == null); + while(visualiserInput.getRaceStatus() == null);//TODO probably remove this. + countdownTimer(); } @@ -135,20 +139,40 @@ public class StartController extends Controller implements Observer { @Override public void update(Observable o, Object arg) { if(o instanceof StreamedCourse) { - if(((StreamedCourse) o).hasReadBoats()) { + StreamedCourse streamedCourse = (StreamedCourse) o; + if(streamedCourse.hasReadBoats()) { initialiseTables(); } - if(((StreamedCourse)o).hasReadRegatta()) { - Platform.runLater(() -> raceTitleLabel.setText(((StreamedCourse)o).getRegattaName())); + if(streamedCourse.hasReadRegatta()) { + Platform.runLater(() -> raceTitleLabel.setText(streamedCourse.getRegattaName())); } - if (((StreamedCourse) o).hasReadCourse()) { + if (streamedCourse.hasReadCourse()) { Platform.runLater(() -> { setRaceClock(); - while(visualiserInput.getRaceStatus() == null); // TODO - replace with observer on VisualiserInput + if(visualiserInput.getRaceStatus() == null){ + return;//TEMP BUG FIX if the race isn't sending race status messages (our mock currently doesn't), then it would block the javafx thread with the previous while loop. + }; // TODO - replace with observer on VisualiserInput setStartingTime(); setCurrentTime(); }); } + + //TODO this is a somewhat temporary fix for when not all of the race data (boats, course, regatta) is received in time. + //Previously, startRaceNoScaling was called in the enterLobby function after the visualiserInput was started, but when connecting to the official data source it sometimes didn't send all of the race data, causing startRaceNoScaling to start, even though we didn't have enough information to start it. + if (streamedCourse.hasReadBoats() && streamedCourse.hasReadCourse() && streamedCourse.hasReadRegatta()) { + Platform.runLater(() -> { + if (!this.hasRaceStarted) { + if(visualiserInput.getRaceStatus() == null) { + return;//TEMP + } + else { + this.hasRaceStarted = true; + startRaceNoScaling(); + } + } + }); + } + } } @@ -161,7 +185,7 @@ public class StartController extends Controller implements Observer { try { visualiserInput = new VisualiserInput(socket, raceData); new Thread(visualiserInput).start(); - startRaceNoScaling(); + } catch (IOException e) { e.printStackTrace(); }