diff --git a/src/ride/ride.c b/src/ride/ride.c index 3503d8067a..6f41043b43 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -5157,6 +5157,15 @@ int ride_is_valid_for_open(int rideIndex, int goingToBeOpen, int isApplying) ride = get_ride(rideIndex); + // Check to see if construction tool in use. If it is close the construction window + // to set the track to its final state and clean up ghosts. + // We can't just call close as it would cause a stack overflow during shop creation + // with auto open on. + if (WC_RIDE_CONSTRUCTION == RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWCLASS, rct_windowclass) && + rideIndex == RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWNUMBER, rct_windownumber) && + (gInputFlags & INPUT_FLAG_TOOL_ACTIVE)) + window_close_by_number(WC_RIDE_CONSTRUCTION, rideIndex); + stationIndex = ride_mode_check_station_present(ride); if (stationIndex == -1)return 0; diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 7ee5d077eb..ba48e57eb7 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -6597,9 +6597,6 @@ void sub_6DBF3E(rct_vehicle *vehicle) trackType, 0 ); - if (mapElement == NULL) { - return; - } if (RCT2_GLOBAL(0x00F64E1C, uint32) == 0xFFFFFFFF) { RCT2_GLOBAL(0x00F64E1C, uint32) = (mapElement->properties.track.sequence >> 4) & 7; } @@ -6666,9 +6663,6 @@ bool vehicle_update_track_motion_forwards_get_new_track(rct_vehicle *vehicle, ui trackType, 0 ); - if (mapElement == NULL) { - return false; - } if (trackType == TRACK_ELEM_CABLE_LIFT_HILL && vehicle == RCT2_GLOBAL(0x00F64E04, rct_vehicle*)) { RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_11; } diff --git a/src/windows/ride_construction.c b/src/windows/ride_construction.c index db7fc81fd8..c9c3b4eef3 100644 --- a/src/windows/ride_construction.c +++ b/src/windows/ride_construction.c @@ -592,6 +592,7 @@ static void window_ride_construction_close(rct_window *w) uint8 rideIndex = _currentRideIndex; if (ride_try_get_origin_element(rideIndex, NULL)) { rct_ride *ride = get_ride(rideIndex); + // Auto open shops if required. if (ride->mode == RIDE_MODE_SHOP_STALL && gConfigGeneral.auto_open_shops) { ride_set_status(rideIndex, RIDE_STATUS_OPEN); } @@ -1928,12 +1929,6 @@ static void window_ride_construction_exit_click(rct_window *w) */ static void window_ride_construction_update(rct_window *w) { - rct_ride *ride = get_ride(_currentRideIndex); - if (ride == NULL || ride->status != RIDE_STATUS_CLOSED || _deferClose) { - window_close(w); - return; - } - switch (_currentTrackCurve) { case 429: case 376: