fix very rare null pointer exception

This commit is contained in:
Leijurv 2018-09-21 22:14:18 -07:00
parent 9661ab3b42
commit 8b307f296a
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
2 changed files with 14 additions and 1 deletions

View File

@ -90,6 +90,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
int pathingMaxChunkBorderFetch = Baritone.settings().pathingMaxChunkBorderFetch.get(); // grab all settings beforehand so that changing settings during pathing doesn't cause a crash or unpredictable behavior
double favorCoeff = Baritone.settings().backtrackCostFavoringCoefficient.get();
boolean minimumImprovementRepropagation = Baritone.settings().minimumImprovementRepropagation.get();
loopBegin();
while (!openSet.isEmpty() && numEmptyChunk < pathingMaxChunkBorderFetch && System.nanoTime() / 1000000L - timeoutTime < 0 && !cancelRequested) {
if (slowPath) {
try {
@ -180,6 +181,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
}
System.out.println(numMovementsConsidered + " movements considered");
System.out.println("Open set size: " + openSet.size());
System.out.println("PathNode map size: " + mapSize());
System.out.println((int) (numNodes * 1.0 / ((System.nanoTime() / 1000000L - startTime) / 1000F)) + " nodes per second");
double bestDist = 0;
for (int i = 0; i < bestSoFar.length; i++) {

View File

@ -85,7 +85,6 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
}
this.cancelRequested = false;
try {
currentlyRunning = this;
Optional<IPath> path = calculate0(timeout);
path.ifPresent(IPath::postprocess);
isFinished = true;
@ -97,6 +96,14 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
}
}
/**
* Don't set currentlyRunning to this until everything is all ready to go, and we're about to enter the main loop.
* For example, bestSoFar is null so bestPathSoFar (which gets bestSoFar[0]) could NPE if we set currentlyRunning before calculate0
*/
protected void loopBegin() {
currentlyRunning = this;
}
protected abstract Optional<IPath> calculate0(long timeout);
/**
@ -143,6 +150,10 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
return Optional.ofNullable(mostRecentConsidered).map(node -> new Path(startNode, node, 0, goal));
}
protected int mapSize() {
return map.size();
}
@Override
public Optional<IPath> bestPathSoFar() {
if (startNode == null || bestSoFar[0] == null) {