From 32fda83d3916197a46215c83ddd85b2e50128a02 Mon Sep 17 00:00:00 2001 From: PeterN Date: Sat, 30 Mar 2019 22:19:50 +0000 Subject: Fix aa7ca7fe6: Linkgraph node index order must be maintained due to other references. (#7431) Linkgraph nodes require a specific order that was maintained by swapping just the last element for the node to be removed. std::vector::erase() changed this to removing the node is then shuffling the remain items down, which upsets other references to this indices. This is fixed by switching back to the original swap & pop method. --- src/linkgraph/linkgraph.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/linkgraph/linkgraph.cpp b/src/linkgraph/linkgraph.cpp index d8cbf9b50..234b0be60 100644 --- a/src/linkgraph/linkgraph.cpp +++ b/src/linkgraph/linkgraph.cpp @@ -139,7 +139,10 @@ void LinkGraph::RemoveNode(NodeID id) node_edges[id] = node_edges[last_node]; } Station::Get(this->nodes[last_node].station)->goods[this->cargo].node = id; - this->nodes.erase(this->nodes.begin() + id); + /* Erase node by swapping with the last element. Node index is referenced + * directly from station goods entries so the order and position must remain. */ + this->nodes[id] = this->nodes.back(); + this->nodes.pop_back(); this->edges.EraseColumn(id); /* Not doing EraseRow here, as having the extra invalid row doesn't hurt * and removing it would trigger a lot of memmove. The data has already -- cgit v1.2.3-70-g09d2