mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-01-10 02:53:50 +01:00
Avoid NPE during navigation write (#4975)
- Guard for unexpected null entries in train navigation during serialisation
This commit is contained in:
parent
b7a082c408
commit
f91afb2975
1 changed files with 14 additions and 0 deletions
|
@ -735,6 +735,20 @@ public class Navigation {
|
|||
CompoundTag tag = new CompoundTag();
|
||||
if (destination == null)
|
||||
return tag;
|
||||
|
||||
// Remove null values in train navigation fixing a rare crash that could occur
|
||||
List<Couple<TrackNode>> toRemove = new ArrayList<>();
|
||||
for (Couple<TrackNode> couple : currentPath) {
|
||||
if (couple == null || couple.getFirst() == null || couple.getSecond() == null)
|
||||
toRemove.add(couple);
|
||||
}
|
||||
if (toRemove.size() > 0) {
|
||||
Create.LOGGER.error("Found null values in path of train with name: "+train.name.getString()+", id: "+train.id.toString());
|
||||
}
|
||||
for (Couple<TrackNode> brokenCouple : toRemove) {
|
||||
currentPath.remove(brokenCouple);
|
||||
}
|
||||
|
||||
tag.putUUID("Destination", destination.id);
|
||||
tag.putDouble("DistanceToDestination", distanceToDestination);
|
||||
tag.putDouble("DistanceStartedAt", distanceStartedAt);
|
||||
|
|
Loading…
Reference in a new issue