don't cause exception on main thread if a movement becomes impossible

This commit is contained in:
Leijurv 2018-09-23 08:13:21 -07:00
parent 65a59cb739
commit 7fa6e001e6
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
2 changed files with 13 additions and 2 deletions

View File

@ -147,7 +147,12 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
@Override
public Optional<IPath> pathToMostRecentNodeConsidered() {
return Optional.ofNullable(mostRecentConsidered).map(node -> new Path(startNode, node, 0, goal));
try {
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() {
@ -164,7 +169,12 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
continue;
}
if (getDistFromStartSq(bestSoFar[i]) > MIN_DIST_PATH * MIN_DIST_PATH) { // square the comparison since distFromStartSq is squared
return Optional.of(new Path(startNode, bestSoFar[i], 0, goal));
try {
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

View File

@ -107,6 +107,7 @@ class Path implements IPath {
return move;
}
}
// leave this as IllegalStateException; it's caught in AbstractNodeCostSearch
throw new IllegalStateException("Movement became impossible during calculation " + src + " " + dest + " " + dest.subtract(src));
}