From a21a04d451c9c960a1816d61a4759073f44c9d2e Mon Sep 17 00:00:00 2001 From: staphen Date: Mon, 27 Jan 2025 19:10:56 -0500 Subject: [PATCH] Fix off-by-one in path finding logic --- Source/engine/path.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/engine/path.cpp b/Source/engine/path.cpp index 08e546079..06affadc5 100644 --- a/Source/engine/path.cpp +++ b/Source/engine/path.cpp @@ -160,13 +160,13 @@ int ReconstructPath(const ExploredNodes &explored, PointT dest, int8_t *path, si const auto it = explored.find(cur); if (it == explored.end()) app_fatal("Failed to reconstruct path"); if (it->second.g == 0) break; // reached start - path[len++] = GetPathDirection(it->second.prev, cur); - cur = it->second.prev; if (len == maxPathLength) { // Path too long. len = 0; break; } + path[len++] = GetPathDirection(it->second.prev, cur); + cur = it->second.prev; } std::reverse(path, path + len); std::fill(path + len, path + maxPathLength, -1);