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
|
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();
|
double favorCoeff = Baritone.settings().backtrackCostFavoringCoefficient.get();
|
||||||
boolean minimumImprovementRepropagation = Baritone.settings().minimumImprovementRepropagation.get();
|
boolean minimumImprovementRepropagation = Baritone.settings().minimumImprovementRepropagation.get();
|
||||||
|
loopBegin();
|
||||||
while (!openSet.isEmpty() && numEmptyChunk < pathingMaxChunkBorderFetch && System.nanoTime() / 1000000L - timeoutTime < 0 && !cancelRequested) {
|
while (!openSet.isEmpty() && numEmptyChunk < pathingMaxChunkBorderFetch && System.nanoTime() / 1000000L - timeoutTime < 0 && !cancelRequested) {
|
||||||
if (slowPath) {
|
if (slowPath) {
|
||||||
try {
|
try {
|
||||||
@ -180,6 +181,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
|||||||
}
|
}
|
||||||
System.out.println(numMovementsConsidered + " movements considered");
|
System.out.println(numMovementsConsidered + " movements considered");
|
||||||
System.out.println("Open set size: " + openSet.size());
|
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");
|
System.out.println((int) (numNodes * 1.0 / ((System.nanoTime() / 1000000L - startTime) / 1000F)) + " nodes per second");
|
||||||
double bestDist = 0;
|
double bestDist = 0;
|
||||||
for (int i = 0; i < bestSoFar.length; i++) {
|
for (int i = 0; i < bestSoFar.length; i++) {
|
||||||
|
@ -85,7 +85,6 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
|
|||||||
}
|
}
|
||||||
this.cancelRequested = false;
|
this.cancelRequested = false;
|
||||||
try {
|
try {
|
||||||
currentlyRunning = this;
|
|
||||||
Optional<IPath> path = calculate0(timeout);
|
Optional<IPath> path = calculate0(timeout);
|
||||||
path.ifPresent(IPath::postprocess);
|
path.ifPresent(IPath::postprocess);
|
||||||
isFinished = true;
|
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);
|
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));
|
return Optional.ofNullable(mostRecentConsidered).map(node -> new Path(startNode, node, 0, goal));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected int mapSize() {
|
||||||
|
return map.size();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<IPath> bestPathSoFar() {
|
public Optional<IPath> bestPathSoFar() {
|
||||||
if (startNode == null || bestSoFar[0] == null) {
|
if (startNode == null || bestSoFar[0] == null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user