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 fa5fc66
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
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 fa5fc66

Please sign in to comment.