From 7ac181f33dcca0b2b3ef9d6a57747d1a4c009853 Mon Sep 17 00:00:00 2001 From: Joseph Gardner Date: Wed, 27 Sep 2017 13:08:29 +1300 Subject: [PATCH] Fixed null pointer when race finishes #story[1299] --- .../Controllers/NextMarkController.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/racevisionGame/src/main/java/visualiser/Controllers/NextMarkController.java b/racevisionGame/src/main/java/visualiser/Controllers/NextMarkController.java index 7370246f..20da6f3c 100644 --- a/racevisionGame/src/main/java/visualiser/Controllers/NextMarkController.java +++ b/racevisionGame/src/main/java/visualiser/Controllers/NextMarkController.java @@ -49,9 +49,13 @@ public class NextMarkController { AnimationTimer arrow2d = new AnimationTimer() { @Override public void handle(long now) { - CompoundMark target = boat.getCurrentLeg().getEndCompoundMark(); - Bearing headingToMark = GPSCoordinate.calculateBearing(boat.getPosition(), target.getAverageGPSCoordinate()); - arrowStackPane2d.setRotate(headingToMark.degrees()); + if (boat.getCurrentLeg().getEndCompoundMark() != null) { + CompoundMark target = boat.getCurrentLeg().getEndCompoundMark(); + Bearing headingToMark = GPSCoordinate.calculateBearing(boat.getPosition(), target.getAverageGPSCoordinate()); + arrowStackPane2d.setRotate(headingToMark.degrees()); + } else { + stop(); + } } }; arrow2d.start(); @@ -73,10 +77,14 @@ public class NextMarkController { AnimationTimer arrow3d = new AnimationTimer() { @Override public void handle(long now) { - arrow.getTransforms().clear(); - double zRotation = calculateZRotate(); - arrow.setRotate(calculateXRotate(zRotation)); - arrow.getTransforms().add(new Rotate(zRotation, new Point3D(0, 0, 1))); + if (boat.getCurrentLeg().getEndCompoundMark() != null) { + arrow.getTransforms().clear(); + double zRotation = calculateZRotate(); + arrow.setRotate(calculateXRotate(zRotation)); + arrow.getTransforms().add(new Rotate(zRotation, new Point3D(0, 0, 1))); + } else { + stop(); + } } }; arrow3d.start();