From d9a565dd2109a4002ed0c266e20b7f4243af4ca0 Mon Sep 17 00:00:00 2001 From: Matthias Moninger <5415177+ZehMatt@users.noreply.github.com> Date: Thu, 15 Jun 2023 22:27:00 +0300 Subject: [PATCH] Fix #20361: Crash when using random map generation (#20400) * Fix #20361: Crash using map generation * Update changelog.txt --- distribution/changelog.txt | 1 + src/openrct2/world/MapGen.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index d281193842..95a06ead0f 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -12,6 +12,7 @@ - Fix: [#20155] Fairground organ style 2 shows up as regular music, rather than for the merry-go-round. - Fix: [#20260] Ride locks up when inspecting/fixing staff member is fired. - Fix: [#20262] Title screen music missing when “random” title music is selected and RCT1 is no longer linked. +- Fix: [#20361] Crash when using random map generation. 0.4.5 (2023-05-08) ------------------------------------------------------------------------ diff --git a/src/openrct2/world/MapGen.cpp b/src/openrct2/world/MapGen.cpp index 56acdf186c..d3a24b318f 100644 --- a/src/openrct2/world/MapGen.cpp +++ b/src/openrct2/world/MapGen.cpp @@ -370,7 +370,7 @@ static void MapGenPlaceTrees() neighbourPos.y = std::clamp(neighbourPos.y, COORDS_XY_STEP, COORDS_XY_STEP * (gMapSize.y - 1)); const auto neighboutSurface = MapGetSurfaceElementAt(neighbourPos); - if (neighboutSurface->GetWaterHeight() > 0) + if (neighboutSurface != nullptr && neighboutSurface->GetWaterHeight() > 0) { float distance = std::sqrt(offsetX * offsetX + offsetY * offsetY); oasisScore += 0.5f / (maxOasisDistance * distance);