mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Safely handle block deletion (#13315)
Co-authored-by: Jude Melton-Houghton <jwmhjwmh@gmail.com>
This commit is contained in:
parent
f3b198e490
commit
ed632f3854
7 changed files with 74 additions and 5 deletions
23
src/map.cpp
23
src/map.cpp
|
@ -1309,6 +1309,8 @@ ServerMap::~ServerMap()
|
|||
*/
|
||||
delete dbase;
|
||||
delete dbase_ro;
|
||||
|
||||
deleteDetachedBlocks();
|
||||
}
|
||||
|
||||
MapgenParams *ServerMap::getMapgenParams()
|
||||
|
@ -1888,12 +1890,31 @@ bool ServerMap::deleteBlock(v3s16 blockpos)
|
|||
MapSector *sector = getSectorNoGenerate(p2d);
|
||||
if (!sector)
|
||||
return false;
|
||||
sector->deleteBlock(block);
|
||||
// It may not be safe to delete the block from memory at the moment
|
||||
// (pointers to it could still be in use)
|
||||
sector->detachBlock(block);
|
||||
m_detached_blocks.push_back(block);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ServerMap::deleteDetachedBlocks()
|
||||
{
|
||||
for (MapBlock *block : m_detached_blocks) {
|
||||
assert(block->isOrphan());
|
||||
delete block;
|
||||
}
|
||||
m_detached_blocks.clear();
|
||||
}
|
||||
|
||||
void ServerMap::step()
|
||||
{
|
||||
// Delete from memory blocks removed by deleteBlocks() only when pointers
|
||||
// to them are (probably) no longer in use
|
||||
deleteDetachedBlocks();
|
||||
}
|
||||
|
||||
void ServerMap::PrintInfo(std::ostream &out)
|
||||
{
|
||||
out<<"ServerMap: ";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue