From 08ff1ab93e53db2e59326c76a45a589f3379cb28 Mon Sep 17 00:00:00 2001 From: Kuhnovic <68320206+Kuhnovic@users.noreply.github.com> Date: Fri, 8 Mar 2024 23:46:13 +0100 Subject: [PATCH] Fix #12236: Ship pathfinder causes crash when ship is already at destination (#12238) --- src/pathfinder/yapf/yapf_ship.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pathfinder/yapf/yapf_ship.cpp b/src/pathfinder/yapf/yapf_ship.cpp index bf07e2c448..8fe1701948 100644 --- a/src/pathfinder/yapf/yapf_ship.cpp +++ b/src/pathfinder/yapf/yapf_ship.cpp @@ -263,7 +263,10 @@ public: } node = node->m_parent; } - assert(!path_cache.empty()); + + /* A empty path means we are already at the destination. The pathfinder shouldn't have been called at all. + * Return a random reachable trackdir to hopefully nudge the ship out of this strange situation. */ + if (path_cache.empty()) return GetRandomFollowUpTrackdir(v, src_tile, trackdir, true); /* Take out the last trackdir as the result. */ const Trackdir result = path_cache.front();