From 6fd2eb91a2194bc129717077f45afea34e0982f8 Mon Sep 17 00:00:00 2001 From: ZehMatt Date: Sat, 7 Oct 2017 14:48:54 +0200 Subject: [PATCH] Fix demolishing rides causing errors. --- src/openrct2/windows/RideConstruction.cpp | 29 ++++++++++++++++------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/openrct2/windows/RideConstruction.cpp b/src/openrct2/windows/RideConstruction.cpp index dfab8b936d..272850ff07 100644 --- a/src/openrct2/windows/RideConstruction.cpp +++ b/src/openrct2/windows/RideConstruction.cpp @@ -644,13 +644,24 @@ static void window_ride_construction_close(rct_window *w) hide_gridlines(); uint8 rideIndex = _currentRideIndex; - if (ride_try_get_origin_element(rideIndex, nullptr)) { - Ride *ride = get_ride(rideIndex); + Ride * ride = get_ride(rideIndex); + + // If we demolish a ride all windows will be closed including the construction window, + // the ride at this point is already gone. + if (ride == nullptr || ride->type == RIDE_TYPE_NULL) + { + return; + } + + if (ride_try_get_origin_element(rideIndex, nullptr)) + { // Auto open shops if required. - if (ride->mode == RIDE_MODE_SHOP_STALL && gConfigGeneral.auto_open_shops) { + if (ride->mode == RIDE_MODE_SHOP_STALL && gConfigGeneral.auto_open_shops) + { // HACK: Until we find a good a way to defer the game command for opening the shop, stop this // from getting stuck in an infinite loop as opening the ride will try to close this window - if (!_autoOpeningShop) { + if (!_autoOpeningShop) + { _autoOpeningShop = true; ride_set_status(rideIndex, RIDE_STATUS_OPEN); _autoOpeningShop = false; @@ -658,14 +669,14 @@ static void window_ride_construction_close(rct_window *w) } ride_set_to_default_inspection_interval(rideIndex); - window_ride_main_open(rideIndex); - } else { - sint32 eax = gGamePaused; - + } + else + { + sint32 previousPauseState = gGamePaused; gGamePaused = 0; ride_demolish(rideIndex, GAME_COMMAND_FLAG_APPLY); - gGamePaused = eax; + gGamePaused = previousPauseState; } }