diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 28ad1ea2fe..50baa5f9d8 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -432,10 +432,11 @@ static std::array _vehicle_tile_hash{}; VehiclesNearTileXY::Iterator::Iterator(int32_t x, int32_t y) { const int COLL_DIST = 6; - pos_rect.left = x - COLL_DIST; - pos_rect.right = x + COLL_DIST; - pos_rect.top = y - COLL_DIST; - pos_rect.bottom = y + COLL_DIST; + /* There are no negative tile coordinates */ + pos_rect.left = std::max(0, x - COLL_DIST); + pos_rect.right = std::max(0, x + COLL_DIST); + pos_rect.top = std::max(0, y - COLL_DIST); + pos_rect.bottom = std::max(0, y + COLL_DIST); /* Hash area to scan */ this->hxmin = this->hx = GetTileHash1D(pos_rect.left / TILE_SIZE);