Skip to content

Commit

Permalink
Fix OpenRCT2#21748: TileElement out of bounds
Browse files Browse the repository at this point in the history
This fixes crashes observed and allows the park to load. The park is
overlarge and breaks some assumptions we have in our code.
  • Loading branch information
janisozaur committed May 2, 2024
1 parent 4e8f578 commit 2334268
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions distribution/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
27 changes: 24 additions & 3 deletions src/openrct2/world/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,14 @@ int32_t TileElementIteratorNext(TileElementIterator* it)
if (it->element == nullptr)
{
it->element = MapGetFirstElementAt(TileCoordsXY{ it->x, it->y });
return 1;
if (it->element == nullptr)
{
return 0;
}
else
{
return 1;
}
}

if (!it->element->IsLastForTile())
Expand All @@ -314,15 +321,29 @@ int32_t TileElementIteratorNext(TileElementIterator* it)
{
it->y++;
it->element = MapGetFirstElementAt(TileCoordsXY{ it->x, it->y });
return 1;
if (it->element == nullptr)
{
return 0;
}
else
{
return 1;
}
}

if (it->x < (gameState.MapSize.x - 2))
{
it->y = 1;
it->x++;
it->element = MapGetFirstElementAt(TileCoordsXY{ it->x, it->y });
return 1;
if (it->element == nullptr)
{
return 0;
}
else
{
return 1;
}
}

return 0;
Expand Down
4 changes: 4 additions & 0 deletions src/openrct2/world/MapAnimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down

0 comments on commit 2334268

Please sign in to comment.