diff --git a/src/openttd.cpp b/src/openttd.cpp index 275a8d1d0c..4cb5d17752 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -1489,6 +1489,11 @@ void CheckCaches(bool force_check) assert(memcmp(&st->goods[c].cargo, buff, sizeof(StationCargoList)) == 0); } } + + OrderList *order_list; + FOR_ALL_ORDER_LISTS(order_list) { + order_list->DebugCheckSanity(); + } } /** diff --git a/src/order_base.h b/src/order_base.h index 5db0ab3774..f3d93726f2 100644 --- a/src/order_base.h +++ b/src/order_base.h @@ -701,6 +701,7 @@ public: void FreeChain(bool keep_orderlist = false); void DebugCheckSanity() const; + bool CheckOrderListIndexing() const; /** * Get the vector of all scheduled dispatch slot diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index 5749828f43..2aa18693cd 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -371,6 +371,16 @@ void OrderList::ReindexOrderList() } } +bool OrderList::CheckOrderListIndexing() const +{ + uint idx = 0; + for (Order *o = this->first; o != nullptr; o = o->next, idx++) { + if (idx >= this->order_index.size()) return false; + if (this->order_index[idx] != o) return false; + } + return idx == this->order_index.size(); +} + /** * Recomputes everything. * @param chain first order in the chain @@ -778,6 +788,7 @@ void OrderList::DebugCheckSanity() const DEBUG(misc, 6, "... detected %u orders (%u manual), %u vehicles, %i timetabled, %i total", (uint)this->GetNumOrders(), (uint)this->num_manual_orders, this->num_vehicles, this->timetable_duration, this->total_duration); + assert(this->CheckOrderListIndexing()); } /**