Fix demolishing rides causing errors.

This commit is contained in:
ZehMatt 2017-10-07 14:48:54 +02:00 committed by Michael Steenbeek
parent 19f9a9b755
commit 6fd2eb91a2
1 changed files with 20 additions and 9 deletions

View File

@ -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;
}
}