aboutsummaryrefslogtreecommitdiff
path: root/src/mapsector.cpp
diff options
context:
space:
mode:
authorDS <ds.desour@proton.me>2023-03-24 12:34:44 +0100
committerGitHub <noreply@github.com>2023-03-24 12:34:44 +0100
commited632f38547e2a63edb1a5dacbc37f3441cc43b6 (patch)
treeadcec37379068ca4a34a3129d2fd66d74558efa1 /src/mapsector.cpp
parentf3b198e49008ea3aba568974c8f423fdc801d4a2 (diff)
downloadminetest-ed632f38547e2a63edb1a5dacbc37f3441cc43b6.tar.xz
Safely handle block deletion (#13315)
Co-authored-by: Jude Melton-Houghton <jwmhjwmh@gmail.com>
Diffstat (limited to 'src/mapsector.cpp')
-rw-r--r--src/mapsector.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/mapsector.cpp b/src/mapsector.cpp
index e6cc32e28..36a61e139 100644
--- a/src/mapsector.cpp
+++ b/src/mapsector.cpp
@@ -110,6 +110,12 @@ void MapSector::insertBlock(MapBlock *block)
void MapSector::deleteBlock(MapBlock *block)
{
+ detachBlock(block);
+ delete block;
+}
+
+void MapSector::detachBlock(MapBlock *block)
+{
s16 block_y = block->getPos().Y;
// Clear from cache
@@ -118,8 +124,8 @@ void MapSector::deleteBlock(MapBlock *block)
// Remove from container
m_blocks.erase(block_y);
- // Delete
- delete block;
+ // Mark as removed
+ block->makeOrphan();
}
void MapSector::getBlocks(MapBlockVect &dest)