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
This commit is contained in:
Jonas Herzig
2019-06-21 12:05:05 +02:00
parent f1f760a0e9
commit 75c4c7213f
2 changed files with 13 additions and 3 deletions

View File

@@ -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<Double, Double, Double> 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<Float, Float, Float> 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

View File

@@ -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<Integer> {
@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