Check cargo action count consistencies on load

Add scope info logging to AfterLoadVehicles
This commit is contained in:
Jonathan G Rennison
2018-05-13 18:56:31 +01:00
parent a60eff174d
commit 38779254e5
2 changed files with 18 additions and 4 deletions

View File

@@ -309,17 +309,26 @@ protected:
template<class Taction> template<class Taction>
void PopCargo(Taction action); void PopCargo(Taction action);
public:
/** /**
* Assert that the designation counts add up. * Assert that the designation counts add up.
*/ */
inline void AssertCountConsistency() const inline void AssertCountConsistency() const
{ {
assert(this->action_counts[MTA_KEEP] + assert_msg(this->action_counts[MTA_KEEP] +
this->action_counts[MTA_DELIVER] + this->action_counts[MTA_DELIVER] +
this->action_counts[MTA_TRANSFER] + this->action_counts[MTA_TRANSFER] +
this->action_counts[MTA_LOAD] == this->count); this->action_counts[MTA_LOAD] == this->count,
"%u + %u + %u + %u != %u",
this->action_counts[MTA_KEEP],
this->action_counts[MTA_DELIVER],
this->action_counts[MTA_TRANSFER],
this->action_counts[MTA_LOAD],
this->count);
} }
protected:
void AddToCache(const CargoPacket *cp); void AddToCache(const CargoPacket *cp);
void RemoveFromCache(const CargoPacket *cp, uint count); void RemoveFromCache(const CargoPacket *cp, uint count);

View File

@@ -20,6 +20,8 @@
#include "../company_base.h" #include "../company_base.h"
#include "../company_func.h" #include "../company_func.h"
#include "../disaster_vehicle.h" #include "../disaster_vehicle.h"
#include "../scope_info.h"
#include "../string_func.h"
#include "saveload.h" #include "saveload.h"
@@ -248,8 +250,8 @@ extern byte _age_cargo_skip_counter; // From misc_sl.cpp
/** Called after load to update coordinates */ /** Called after load to update coordinates */
void AfterLoadVehicles(bool part_of_load) void AfterLoadVehicles(bool part_of_load)
{ {
Vehicle *v; Vehicle *v = nullptr;
SCOPE_INFO_FMT([&v], "AfterLoadVehicles: %s", scope_dumper().VehicleInfo(v));
FOR_ALL_VEHICLES(v) { FOR_ALL_VEHICLES(v) {
/* Reinstate the previous pointer */ /* Reinstate the previous pointer */
if (v->Next() != NULL) v->Next()->previous = v; if (v->Next() != NULL) v->Next()->previous = v;
@@ -326,6 +328,7 @@ void AfterLoadVehicles(bool part_of_load)
/* The road vehicle subtype was converted to a flag. */ /* The road vehicle subtype was converted to a flag. */
RoadVehicle *rv; RoadVehicle *rv;
FOR_ALL_ROADVEHICLES(rv) { FOR_ALL_ROADVEHICLES(rv) {
v = rv;
if (rv->subtype == 0) { if (rv->subtype == 0) {
/* The road vehicle is at the front. */ /* The road vehicle is at the front. */
rv->SetFrontEngine(); rv->SetFrontEngine();
@@ -369,6 +372,7 @@ void AfterLoadVehicles(bool part_of_load)
} }
} }
} }
v = nullptr;
CheckValidVehicles(); CheckValidVehicles();
@@ -469,6 +473,7 @@ void AfterLoadVehicles(bool part_of_load)
v->coord.left = INVALID_COORD; v->coord.left = INVALID_COORD;
v->UpdatePosition(); v->UpdatePosition();
v->UpdateViewport(false); v->UpdateViewport(false);
v->cargo.AssertCountConsistency();
} }
} }