fix very rare null pointer exception
This commit is contained in:
parent
9661ab3b42
commit
8b307f296a
@ -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++) {
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user