diff --git a/src/openttd.cpp b/src/openttd.cpp index 56ecf4072e..7d7067ceae 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -1423,6 +1423,11 @@ void CheckCaches(bool force_check, std::function log) Vehicle *v; FOR_ALL_VEHICLES(v) { + extern bool ValidateVehicleTileHash(const Vehicle *v); + if (!ValidateVehicleTileHash(v)) { + CCLOG("vehicle tile hash mismatch: type %i, vehicle %i, company %i, unit number %i", (int)v->type, v->index, (int)v->owner, v->unitnumber); + } + extern void FillNewGRFVehicleCache(const Vehicle *v); if (v != v->First() || v->vehstatus & VS_CRASHED || !v->IsPrimaryVehicle()) continue; diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 07932435cf..bcc129219f 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -762,6 +762,15 @@ static void UpdateVehicleTileHash(Vehicle *v, bool remove) v->hash_tile_current = new_hash; } +bool ValidateVehicleTileHash(const Vehicle *v) +{ + if (v->type == VEH_TRAIN && Train::From(v)->IsVirtual()) return v->hash_tile_current == nullptr; + + int x = GB(TileX(v->tile), HASH_RES, HASH_BITS); + int y = GB(TileY(v->tile), HASH_RES, HASH_BITS) << HASH_BITS; + return v->hash_tile_current == &_vehicle_tile_hash[(x + y) & TOTAL_HASH_MASK]; +} + static Vehicle *_vehicle_viewport_hash[1 << (GEN_HASHX_BITS + GEN_HASHY_BITS)]; static void UpdateVehicleViewportHash(Vehicle *v, int x, int y)