don't cause exception on main thread if a movement becomes impossible
This commit is contained in:
parent
65a59cb739
commit
7fa6e001e6
@ -147,7 +147,12 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<IPath> pathToMostRecentNodeConsidered() {
|
public Optional<IPath> pathToMostRecentNodeConsidered() {
|
||||||
|
try {
|
||||||
return Optional.ofNullable(mostRecentConsidered).map(node -> new Path(startNode, node, 0, goal));
|
return Optional.ofNullable(mostRecentConsidered).map(node -> new Path(startNode, node, 0, goal));
|
||||||
|
} catch (IllegalStateException ex) {
|
||||||
|
System.out.println("Unable to construct path to render");
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int mapSize() {
|
protected int mapSize() {
|
||||||
@ -164,7 +169,12 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (getDistFromStartSq(bestSoFar[i]) > MIN_DIST_PATH * MIN_DIST_PATH) { // square the comparison since distFromStartSq is squared
|
if (getDistFromStartSq(bestSoFar[i]) > MIN_DIST_PATH * MIN_DIST_PATH) { // square the comparison since distFromStartSq is squared
|
||||||
|
try {
|
||||||
return Optional.of(new Path(startNode, bestSoFar[i], 0, goal));
|
return Optional.of(new Path(startNode, bestSoFar[i], 0, goal));
|
||||||
|
} catch (IllegalStateException ex) {
|
||||||
|
System.out.println("Unable to construct path to render");
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// instead of returning bestSoFar[0], be less misleading
|
// instead of returning bestSoFar[0], be less misleading
|
||||||
|
@ -107,6 +107,7 @@ class Path implements IPath {
|
|||||||
return move;
|
return move;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// leave this as IllegalStateException; it's caught in AbstractNodeCostSearch
|
||||||
throw new IllegalStateException("Movement became impossible during calculation " + src + " " + dest + " " + dest.subtract(src));
|
throw new IllegalStateException("Movement became impossible during calculation " + src + " " + dest + " " + dest.subtract(src));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user