Skip to content

Commit

Permalink
Check psTile->psObject before resetting
Browse files Browse the repository at this point in the history
With the recent changes that may cause script object removals to be queued (and permit building structures on top of structures queued for removal), ensure that `psTile->psObject` is only reset if it matches the object being deleted.
  • Loading branch information
past-due committed Apr 28, 2024
1 parent f96ba15 commit 1f8938a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,10 @@ bool destroyFeature(FEATURE *psDel, unsigned impactTime)
const unsigned int x = b.map.x + width;
const unsigned int y = b.map.y + breadth;
MAPTILE *psTile = mapTile(x, y);
if (psTile->psObject != psDel)
{
continue;
}
// stops water texture changing for underwater features
if (terrainType(psTile) != TER_WATER)
{
Expand Down
7 changes: 5 additions & 2 deletions src/structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4393,8 +4393,11 @@ static void removeStructFromMap(STRUCTURE *psStruct)
for (int i = 0; i < b.size.x; ++i)
{
MAPTILE *psTile = mapTile(b.map.x + i, b.map.y + j);
psTile->psObject = nullptr;
auxClearBlocking(b.map.x + i, b.map.y + j, AIR_BLOCKED);
if (psTile->psObject == psStruct)
{
psTile->psObject = nullptr;
auxClearBlocking(b.map.x + i, b.map.y + j, AIR_BLOCKED);
}
}
}
}
Expand Down

0 comments on commit 1f8938a

Please sign in to comment.