mirror of
https://github.com/luanti-org/luanti.git
synced 2025-11-06 10:15:19 +01:00
Guard new object from being added at shutdown (#16610)
This commit is contained in:
@@ -278,8 +278,12 @@ void ServerEnvironment::init()
|
||||
|
||||
void ServerEnvironment::deactivateBlocksAndObjects()
|
||||
{
|
||||
// Prevent any funny business from happening in case further callbacks
|
||||
// try to add new objects.
|
||||
m_shutting_down = true;
|
||||
|
||||
// Clear active block list.
|
||||
// This makes the next one delete all active objects.
|
||||
// This makes the next code delete all active objects.
|
||||
m_active_blocks.clear();
|
||||
|
||||
deactivateFarObjects(true);
|
||||
@@ -287,6 +291,7 @@ void ServerEnvironment::deactivateBlocksAndObjects()
|
||||
|
||||
ServerEnvironment::~ServerEnvironment()
|
||||
{
|
||||
m_script = nullptr;
|
||||
assert(m_active_blocks.size() == 0); // deactivateBlocksAndObjects does this
|
||||
|
||||
// Drop/delete map
|
||||
@@ -301,9 +306,12 @@ ServerEnvironment::~ServerEnvironment()
|
||||
for (RemotePlayer *m_player : m_players) {
|
||||
delete m_player;
|
||||
}
|
||||
m_players.clear();
|
||||
|
||||
delete m_player_database;
|
||||
m_player_database = nullptr;
|
||||
delete m_auth_database;
|
||||
m_auth_database = nullptr;
|
||||
}
|
||||
|
||||
Map & ServerEnvironment::getMap()
|
||||
@@ -1208,6 +1216,11 @@ void ServerEnvironment::deleteParticleSpawner(u32 id, bool remove_from_object)
|
||||
u16 ServerEnvironment::addActiveObject(std::unique_ptr<ServerActiveObject> object)
|
||||
{
|
||||
assert(object); // Pre-condition
|
||||
if (m_shutting_down) {
|
||||
warningstream << "ServerEnvironment: refusing to add active object "
|
||||
"during shutdown: " << object->getDescription() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
m_added_objects++;
|
||||
u16 id = addActiveObjectRaw(std::move(object), nullptr, 0);
|
||||
return id;
|
||||
@@ -1569,7 +1582,7 @@ std::unique_ptr<ServerActiveObject> ServerEnvironment::createSAO(ActiveObjectTyp
|
||||
*/
|
||||
void ServerEnvironment::activateObjects(MapBlock *block, u32 dtime_s)
|
||||
{
|
||||
if (block == NULL)
|
||||
if (!block || m_shutting_down)
|
||||
return;
|
||||
|
||||
if (!block->onObjectsActivation())
|
||||
|
||||
Reference in New Issue
Block a user