diff options
author | Vít Šefl <vituscze@gmail.com> | 2021-05-17 22:32:30 +0200 |
---|---|---|
committer | rubidium42 <rubidium42@users.noreply.github.com> | 2021-05-29 19:00:47 +0200 |
commit | 0125ba82e8b94461894a9628dea6552c0bbfa38d (patch) | |
tree | 56589b0c56546dd40560a984b45211e5af93f902 /src | |
parent | 7713c3e3ccdb8dea2924cc11a7108f227e374232 (diff) | |
download | openttd-0125ba82e8b94461894a9628dea6552c0bbfa38d.tar.xz |
Fix: Do not send vehicles towards incomplete PF nodes
YAPF could end up in a situation where it sets the best intermediate node
to a node whose construction is never finalized (i.e. it is never added to
the open list). The content of the node would be overwritten in the next
round, potentially sending the vehicle to an unwanted location.
Diffstat (limited to 'src')
-rw-r--r-- | src/pathfinder/yapf/yapf_base.hpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/pathfinder/yapf/yapf_base.hpp b/src/pathfinder/yapf/yapf_base.hpp index 41c38ab34..c548cfd97 100644 --- a/src/pathfinder/yapf/yapf_base.hpp +++ b/src/pathfinder/yapf/yapf_base.hpp @@ -252,9 +252,9 @@ public: return; } - if (m_max_search_nodes > 0 && (m_pBestIntermediateNode == nullptr || (m_pBestIntermediateNode->GetCostEstimate() - m_pBestIntermediateNode->GetCost()) > (n.GetCostEstimate() - n.GetCost()))) { - m_pBestIntermediateNode = &n; - } + /* The new node can be set as the best intermediate node only once we're + * certain it will be finalized by being inserted into the open list. */ + bool set_intermediate = m_max_search_nodes > 0 && (m_pBestIntermediateNode == nullptr || (m_pBestIntermediateNode->GetCostEstimate() - m_pBestIntermediateNode->GetCost()) > (n.GetCostEstimate() - n.GetCost())); /* check new node against open list */ Node *openNode = m_nodes.FindOpenNode(n.GetKey()); @@ -267,6 +267,7 @@ public: *openNode = n; /* add the updated old node back to open list */ m_nodes.InsertOpenNode(*openNode); + if (set_intermediate) m_pBestIntermediateNode = openNode; } return; } @@ -292,6 +293,7 @@ public: /* the new node is really new * add it to the open list */ m_nodes.InsertOpenNode(n); + if (set_intermediate) m_pBestIntermediateNode = &n; } const VehicleType * GetVehicle() const |