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 Apr 7, 2024
1 parent 828eb0e commit c25c4d5
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
@@ -1,5 +1,6 @@
0.4.11 (in development)
------------------------------------------------------------------------
- Fix: [#21749] Crash when loading park bigger than current limits.

0.4.10 (2024-04-02)
------------------------------------------------------------------------
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 @@ -301,7 +301,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 @@ -315,15 +322,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 c25c4d5

Please sign in to comment.