From a088f7615b1c9f22b03dc7a7e60149eb1226bd32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Thu, 2 May 2024 18:14:22 +0200 Subject: [PATCH] Fix #21748: TileElement out of bounds (#21749) * Fix #21748: TileElement out of bounds This fixes crashes observed and allows the park to load. The park is overlarge and breaks some assumptions we have in our code. * Use ternaries for checking conditions --- distribution/changelog.txt | 1 + src/openrct2/world/Map.cpp | 6 +++--- src/openrct2/world/MapAnimation.cpp | 4 ++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index b0fb37a7d6..ea327ed55e 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -12,6 +12,7 @@ - Fix: [#18723, #21870] Attempting to demolish a flat ride in pause mode allows you to place multiple copies. - Fix: [#19559] Custom rides with long descriptions extend into lower widgets. - Fix: [#21696] Fullscreen window option not correctly applied on macOS. +- Fix: [#21749] Crash when loading park bigger than current limits. - Fix: [#21787] Map generator heightmap should respect increased height limits. - Fix: [#21829] When creating a new scenario, the default name contains formatting codes. - Fix: [#21937] Build errors with the ORIGINAL_RATINGS flag. diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 4c28730c5a..bca8e1bf62 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -300,7 +300,7 @@ int32_t TileElementIteratorNext(TileElementIterator* it) if (it->element == nullptr) { it->element = MapGetFirstElementAt(TileCoordsXY{ it->x, it->y }); - return 1; + return it->element == nullptr ? 0 : 1; } if (!it->element->IsLastForTile()) @@ -314,7 +314,7 @@ int32_t TileElementIteratorNext(TileElementIterator* it) { it->y++; it->element = MapGetFirstElementAt(TileCoordsXY{ it->x, it->y }); - return 1; + return it->element == nullptr ? 0 : 1; } if (it->x < (gameState.MapSize.x - 2)) @@ -322,7 +322,7 @@ int32_t TileElementIteratorNext(TileElementIterator* it) it->y = 1; it->x++; it->element = MapGetFirstElementAt(TileCoordsXY{ it->x, it->y }); - return 1; + return it->element == nullptr ? 0 : 1; } return 0; diff --git a/src/openrct2/world/MapAnimation.cpp b/src/openrct2/world/MapAnimation.cpp index f582b0eda4..9c1751d48b 100644 --- a/src/openrct2/world/MapAnimation.cpp +++ b/src/openrct2/world/MapAnimation.cpp @@ -619,6 +619,10 @@ void MapAnimationAutoCreate() void MapAnimationAutoCreateAtTileElement(TileCoordsXY coords, TileElement* el) { + if (el == nullptr) + { + return; + } auto loc = CoordsXYZ{ coords.ToCoordsXY(), el->GetBaseZ() }; switch (el->GetType()) {