Skip to content

Commit

Permalink
Fix OpenRCT2#8873: null dereference when trying to place footpath.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZehMatt committed Mar 15, 2019
1 parent 1d9b17a commit 9264b54
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/openrct2/actions/FootpathSceneryPlaceAction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ DEFINE_GAME_ACTION(FootpathSceneryPlaceAction, GAME_COMMAND_PLACE_FOOTPATH_SCENE
}

auto tileElement = map_get_footpath_element(_loc.x / 32, _loc.y / 32, _loc.z / 8);
auto pathElement = tileElement->AsPath();

if (pathElement == nullptr)
if (tileElement == nullptr)
{
log_error("Could not find path element.");
return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_CANT_POSITION_THIS_HERE);
}

auto pathElement = tileElement->AsPath();

// No change
if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST) && pathElement->GetAddition() == _pathItemType
&& !(pathElement->IsBroken()))
Expand Down
6 changes: 3 additions & 3 deletions src/openrct2/world/Footpath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ static bool entrance_has_direction(TileElement* tileElement, int32_t direction)

TileElement* map_get_footpath_element(int32_t x, int32_t y, int32_t z)
{
TileElement* tileElement;

tileElement = map_get_first_element_at(x, y);
TileElement* tileElement = map_get_first_element_at(x, y);
do
{
if (tileElement == nullptr)
break;
if (tileElement->GetType() == TILE_ELEMENT_TYPE_PATH && tileElement->base_height == z)
return tileElement;
} while (!(tileElement++)->IsLastForTile());
Expand Down

0 comments on commit 9264b54

Please sign in to comment.