From 005892bfdbc997b6eee5b53d08997f7aad1bff5a Mon Sep 17 00:00:00 2001 From: Kuhnovic <68320206+Kuhnovic@users.noreply.github.com> Date: Sun, 10 Mar 2024 15:37:56 +0100 Subject: [PATCH] Fix #12250: YAPF Trivial rail pathfinding crashes due to #12217 (#12258) --- src/pathfinder/yapf/yapf_rail.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/pathfinder/yapf/yapf_rail.cpp b/src/pathfinder/yapf/yapf_rail.cpp index 94ec48f127..2d4c44429a 100644 --- a/src/pathfinder/yapf/yapf_rail.cpp +++ b/src/pathfinder/yapf/yapf_rail.cpp @@ -446,6 +446,11 @@ public: this->FindSafePositionOnNode(pPrev); } + + /* If the best PF node has no parent, then there is no (valid) best next trackdir to return. + * This occurs when the PF is called while the train is already at its destination. */ + if (pPrev == nullptr) return INVALID_TRACKDIR; + /* return trackdir from the best origin node (one of start nodes) */ Node &best_next_node = *pPrev; next_trackdir = best_next_node.GetTrackdir();