Skip to content

Commit

Permalink
fix: Filters are now being cleaned up after pathfinding
Browse files Browse the repository at this point in the history
  • Loading branch information
Metaphoriker committed Sep 6, 2024
1 parent 0f6bda7 commit 20071b4
Showing 1 changed file with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ private CompletionStage<PathfinderResult> initiatePathing(
BStatsHandler.increasePathCount();
return pathfinderConfiguration.isAsync()
? CompletableFuture.supplyAsync(
() -> executePathing(start, target, filters, filterStages), PATHING_EXECUTOR)
() -> executePathingAndCleanupFilters(start, target, filters, filterStages),
PATHING_EXECUTOR)
.thenApply(this::finishPathing)
.exceptionally(throwable -> handleException(start, target))
: initiateSyncPathing(start, target, filters, filterStages);
Expand Down Expand Up @@ -200,14 +201,7 @@ private PathfinderResult executePathing(
}

tick(
start,
target,
currentNode,
depth,
nodeQueue,
examinedPositions,
filters,
filterStages);
start, target, currentNode, depth, nodeQueue, examinedPositions, filters, filterStages);
}

aborted = false;
Expand All @@ -229,12 +223,23 @@ private CompletionStage<PathfinderResult> initiateSyncPathing(
List<PathFilterStage> filterStages) {
try {
return CompletableFuture.completedFuture(
executePathing(start, target, filters, filterStages));
executePathingAndCleanupFilters(start, target, filters, filterStages));
} catch (Exception e) {
throw ErrorLogger.logFatalError("Failed to find path sync", e);
}
}

private PathfinderResult executePathingAndCleanupFilters(
PathPosition start,
PathPosition target,
List<PathFilter> filters,
List<PathFilterStage> filterStages) {
PathfinderResult pathfinderResult = executePathing(start, target, filters, filterStages);
filters.forEach(PathFilter::cleanup);
filterStages.forEach(PathFilterStage::cleanup);
return pathfinderResult;
}

private PathfinderResult handleException(PathPosition start, PathPosition target) {
return finishPathing(
new PathfinderResultImpl(
Expand Down

0 comments on commit 20071b4

Please sign in to comment.