From 585f0ef91c0daf83e36e7ed6e1a65fcf18d29d12 Mon Sep 17 00:00:00 2001 From: rubidium Date: Sun, 31 Mar 2013 20:32:21 +0000 Subject: [PATCH] (svn r25133) [1.3] -Backport from trunk: - Fix: Station rebuilding could leave reserved tiles which caused crashes later on [FS#5510, FS#5516] (r25132) - Fix: When the count for a scrollbar was 0, the inter distance was subtracted too much causing a scrollbar with a negative size (r25123) --- src/station_cmd.cpp | 12 ++++++++++-- src/widget.cpp | 3 ++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index dc898d9bcb..d81af5c890 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -1319,8 +1319,16 @@ CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32 TILE_AREA_LOOP(tile, update_reservation_area) { DiagDirection dir = AxisToDiagDir(axis); TileIndexDiff tile_offset = TileOffsByDiagDir(dir); - TileIndex platform_begin = tile - tile_offset * (st->GetPlatformLength(tile, ReverseDiagDir(dir)) - 1); - TileIndex platform_end = tile + tile_offset * (st->GetPlatformLength(tile, dir) - 1); + TileIndex platform_begin = tile; + TileIndex platform_end = tile; + + /* We can only account for tiles that are reachable from this tile, so ignore primarily blocked tiles while finding the platform begin and end. */ + for (TileIndex next_tile = platform_begin - tile_offset; IsCompatibleTrainStationTile(next_tile, platform_begin); next_tile -= tile_offset) { + platform_begin = next_tile; + } + for (TileIndex next_tile = platform_end + tile_offset; IsCompatibleTrainStationTile(next_tile, platform_end); next_tile += tile_offset) { + platform_end = next_tile; + } /* If there is at least on reservation on the platform, we reserve the whole platform. */ bool reservation = false; diff --git a/src/widget.cpp b/src/widget.cpp index c3f9eca299..c96c407138 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -1470,7 +1470,8 @@ void NWidgetMatrix::SetCount(int count) * and post spacing "offsets". */ count = CeilDiv(count, this->sb->IsVertical() ? this->widgets_x : this->widgets_y); count *= (this->sb->IsVertical() ? this->head->smallest_y : this->head->smallest_x) + this->pip_inter; - count += -this->pip_inter + this->pip_pre + this->pip_post; // We counted an inter too much in the multiplication above + if (count > 0) count -= this->pip_inter; // We counted an inter too much in the multiplication above + count += this->pip_pre + this->pip_post; this->sb->SetCount(count); this->sb->SetCapacity(this->sb->IsVertical() ? this->current_y : this->current_x); this->sb->SetStepSize(this->sb->IsVertical() ? this->widget_h : this->widget_w);