Fix crash when removing/upgrading airport with hangar window open

See: https://github.com/OpenTTD/OpenTTD/issues/8809
This commit is contained in:
Jonathan G Rennison
2021-03-07 00:10:46 +00:00
parent 9bf6d1407f
commit 1b146b3bff

View File

@@ -2539,6 +2539,13 @@ CommandCost CmdBuildAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
if (flags & DC_EXEC) {
if (action == AIRPORT_UPGRADE) {
/* delete old airport if upgrading */
for (uint i = 0; i < st->airport.GetNumHangars(); ++i) {
DeleteWindowById(
WC_VEHICLE_DEPOT, st->airport.GetHangarTile(i)
);
}
const AirportSpec *old_as = st->airport.GetSpec();
AirportTileTableIterator old_iter(old_as->table[st->airport.layout], st->airport.tile);
uint old_dist;
@@ -2558,12 +2565,6 @@ CommandCost CmdBuildAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
DeleteNewGRFInspectWindow(GSF_AIRPORTTILES, tile_cur);
}
for (uint i = 0; i < st->airport.GetNumHangars(); ++i) {
DeleteWindowById(
WC_VEHICLE_DEPOT, st->airport.GetHangarTile(i)
);
}
st->rect.AfterRemoveRect(st, st->airport);
st->airport.Clear();
}
@@ -2631,6 +2632,12 @@ static CommandCost RemoveAirport(TileIndex tile, DoCommandFlag flags)
if (cost.Failed()) return cost;
if (flags & DC_EXEC) {
for (uint i = 0; i < st->airport.GetNumHangars(); ++i) {
DeleteWindowById(
WC_VEHICLE_DEPOT, st->airport.GetHangarTile(i)
);
}
ZoningMarkDirtyStationCoverageArea(st);
const AirportSpec *as = st->airport.GetSpec();
/* The noise level is the noise from the airport and reduce it to account for the distance to the town center.
@@ -2651,12 +2658,6 @@ static CommandCost RemoveAirport(TileIndex tile, DoCommandFlag flags)
/* Clear the persistent storage. */
delete st->airport.psa;
for (uint i = 0; i < st->airport.GetNumHangars(); ++i) {
DeleteWindowById(
WC_VEHICLE_DEPOT, st->airport.GetHangarTile(i)
);
}
st->rect.AfterRemoveRect(st, st->airport);
st->airport.Clear();