diff --git a/src/core/pathfinding/algorithms/PriorityQueue.ts b/src/core/pathfinding/algorithms/PriorityQueue.ts index 9f715baad..df7f52919 100644 --- a/src/core/pathfinding/algorithms/PriorityQueue.ts +++ b/src/core/pathfinding/algorithms/PriorityQueue.ts @@ -18,7 +18,20 @@ export class MinHeap implements PriorityQueue { push(node: number, priority: number): void { if (this.size >= this.capacity) { - throw new Error(`MinHeap capacity exceeded: ${this.capacity}`); + console.error( + `MinHeap capacity exceeded (${this.capacity}). ` + + "Resizing, but this indicates a bug. Please investigate.", + ); + + this.capacity *= 2; + + const newHeap = new Int32Array(this.capacity); + const newPri = new Float32Array(this.capacity); + newHeap.set(this.heap); + newPri.set(this.priorities); + + this.heap = newHeap; + this.priorities = newPri; } let i = this.size++; diff --git a/src/core/pathfinding/spatial/SpatialQuery.ts b/src/core/pathfinding/spatial/SpatialQuery.ts index cd7a522eb..defd47aaf 100644 --- a/src/core/pathfinding/spatial/SpatialQuery.ts +++ b/src/core/pathfinding/spatial/SpatialQuery.ts @@ -119,6 +119,10 @@ export class SpatialQuery { const MAX_WAYPOINT_DIST = 200; const PADDING = 10; + if (path.length < MIN_WAYPOINT_DIST) { + return path[0]; + } + const bestTile = path[0]; const map = gm.map(); diff --git a/tests/pathfinding/playground/public/client.js b/tests/pathfinding/playground/public/client.js index 129e98765..c40a5ef9f 100644 --- a/tests/pathfinding/playground/public/client.js +++ b/tests/pathfinding/playground/public/client.js @@ -906,7 +906,8 @@ function updateTransportTimings(result) { hpaTilesEl.textContent = ""; } - const totalTime = result.debug?.timings?.closestShoreByWater || 0; + const totalTime = + result.debug?.timings?.["SpatialQuery.closestShoreByWater"] ?? 0; if (totalTime > 0) { hpaTimeEl.textContent = `${totalTime.toFixed(2)}ms`; hpaTimeEl.classList.remove("faded");