From 75c4c7213f22ce79646e0c94e0e58c7831049019 Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Fri, 21 Jun 2019 12:05:05 +0200 Subject: [PATCH] Fix NPE applying camera keyframes when camera entity is not yet loaded Still not sure when this can happen but users are reporting it: https://www.replaymod.com/forum/thread/2548#post10627 --- .../pathing/properties/CameraProperties.java | 11 +++++++++-- .../pathing/properties/SpectatorProperty.java | 5 ++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/replaymod/pathing/properties/CameraProperties.java b/src/main/java/com/replaymod/pathing/properties/CameraProperties.java index fceec366..cf427cc0 100644 --- a/src/main/java/com/replaymod/pathing/properties/CameraProperties.java +++ b/src/main/java/com/replaymod/pathing/properties/CameraProperties.java @@ -3,6 +3,7 @@ package com.replaymod.pathing.properties; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import com.replaymod.replay.ReplayHandler; +import com.replaymod.replay.camera.CameraEntity; import com.replaymod.replaystudio.pathing.change.Change; import com.replaymod.replaystudio.pathing.property.AbstractProperty; import com.replaymod.replaystudio.pathing.property.AbstractPropertyGroup; @@ -52,7 +53,10 @@ public class CameraProperties extends AbstractPropertyGroup { public void applyToGame(Triple value, @NonNull Object replayHandler) { ReplayHandler handler = ((ReplayHandler) replayHandler); handler.spectateCamera(); - handler.getCameraEntity().setCameraPosition(value.getLeft(), value.getMiddle(), value.getRight()); + CameraEntity cameraEntity = handler.getCameraEntity(); + if (cameraEntity != null) { + cameraEntity.setCameraPosition(value.getLeft(), value.getMiddle(), value.getRight()); + } } @Override @@ -90,7 +94,10 @@ public class CameraProperties extends AbstractPropertyGroup { public void applyToGame(Triple value, @NonNull Object replayHandler) { ReplayHandler handler = ((ReplayHandler) replayHandler); handler.spectateCamera(); - handler.getCameraEntity().setCameraRotation(value.getLeft(), value.getMiddle(), value.getRight()); + CameraEntity cameraEntity = handler.getCameraEntity(); + if (cameraEntity != null) { + cameraEntity.setCameraRotation(value.getLeft(), value.getMiddle(), value.getRight()); + } } @Override diff --git a/src/main/java/com/replaymod/pathing/properties/SpectatorProperty.java b/src/main/java/com/replaymod/pathing/properties/SpectatorProperty.java index 9038e179..a273d8da 100644 --- a/src/main/java/com/replaymod/pathing/properties/SpectatorProperty.java +++ b/src/main/java/com/replaymod/pathing/properties/SpectatorProperty.java @@ -3,6 +3,7 @@ package com.replaymod.pathing.properties; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import com.replaymod.replay.ReplayHandler; +import com.replaymod.replay.camera.CameraEntity; import com.replaymod.replaystudio.pathing.property.AbstractProperty; import com.replaymod.replaystudio.pathing.property.PropertyPart; import com.replaymod.replaystudio.pathing.property.PropertyParts; @@ -32,7 +33,9 @@ public class SpectatorProperty extends AbstractProperty { @Override public void applyToGame(Integer value, Object replayHandler) { ReplayHandler handler = ((ReplayHandler) replayHandler); - World world = handler.getCameraEntity().getEntityWorld(); + CameraEntity cameraEntity = handler.getCameraEntity(); + if (cameraEntity == null) return; + World world = cameraEntity.getEntityWorld(); // Lookup entity by id, returns null if an entity with the id does not exists Entity target = world.getEntityById(value); // Spectate entity, when called with null, returns to camera