From 4aff132fd735dc19e6f9f3f6d53c73ff60f42688 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sat, 16 Dec 2017 12:21:25 +0000 Subject: [PATCH] Fix #6830: Crash when using mountain tool due to ride with no entry --- distribution/changelog.txt | 1 + src/openrct2/world/map.c | 41 +++++++++++++++++++++++++------------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index a07ac2c790..e050fb85ad 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -78,6 +78,7 @@ - Fix: [#6547] The server log is not logged if the server name contains CJK - Fix: [#6593] Cannot hire entertainers when default scenery groups are not selected (original bug). - Fix: [#6657] Guest list is missing tracking icon after reopening. +- Fix: [#6830] Crash when using mountain tool due to ride with no ride entry. - Fix: Infinite loop when removing scenery elements with >127 base height. - Fix: Ghosting of transparent map elements when the viewport is moved in OpenGL mode. - Fix: Clear IME buffer after committing composed text. diff --git a/src/openrct2/world/map.c b/src/openrct2/world/map.c index 3a4dee2d94..5be0bf3e8a 100644 --- a/src/openrct2/world/map.c +++ b/src/openrct2/world/map.c @@ -1573,24 +1573,37 @@ static money32 map_set_land_height(sint32 flags, sint32 x, sint32 y, sint32 heig } while (!tile_element_is_last_for_tile(tileElement++)); } - //Check for ride support limits - if(gCheatsDisableSupportLimits==false) + // Check for ride support limits + if (!gCheatsDisableSupportLimits) { tileElement = map_get_first_element_at(x / 32, y / 32); - do{ - if(tile_element_get_type(tileElement) != TILE_ELEMENT_TYPE_TRACK) - continue; - sint32 rideIndex = track_element_get_ride_index(tileElement); - sint32 maxHeight = get_ride_entry_by_ride(get_ride(rideIndex))->max_height; - if(maxHeight == 0) - maxHeight = RideData5[get_ride(rideIndex)->type].max_height; - sint32 zDelta = tileElement->clearance_height - height; - if(zDelta >= 0 && zDelta/2 > maxHeight) + do + { + if (tile_element_get_type(tileElement) == TILE_ELEMENT_TYPE_TRACK) { - gGameCommandErrorText = STR_SUPPORTS_CANT_BE_EXTENDED; - return MONEY32_UNDEFINED; + sint32 rideIndex = track_element_get_ride_index(tileElement); + Ride * ride = get_ride(rideIndex); + if (ride != NULL) + { + rct_ride_entry * rideEntry = get_ride_entry_by_ride(ride); + if (rideEntry != NULL) + { + sint32 maxHeight = rideEntry->max_height; + if (maxHeight == 0) + { + maxHeight = RideData5[get_ride(rideIndex)->type].max_height; + } + sint32 zDelta = tileElement->clearance_height - height; + if (zDelta >= 0 && zDelta / 2 > maxHeight) + { + gGameCommandErrorText = STR_SUPPORTS_CANT_BE_EXTENDED; + return MONEY32_UNDEFINED; + } + } + } } - }while(!tile_element_is_last_for_tile(tileElement++)); + } + while(!tile_element_is_last_for_tile(tileElement++)); } uint8 zCorner = height; //z position of highest corner of tile