@@ -278,15 +278,20 @@ void ServerEnvironment::init()
278278
279279void ServerEnvironment::deactivateBlocksAndObjects ()
280280{
281+ // Prevent any funny business from happening in case further callbacks
282+ // try to add new objects.
283+ m_shutting_down = true ;
284+
281285 // Clear active block list.
282- // This makes the next one delete all active objects.
286+ // This makes the next code delete all active objects.
283287 m_active_blocks.clear ();
284288
285289 deactivateFarObjects (true );
286290}
287291
288292ServerEnvironment::~ServerEnvironment ()
289293{
294+ m_script = nullptr ;
290295 assert (m_active_blocks.size () == 0 ); // deactivateBlocksAndObjects does this
291296
292297 // Drop/delete map
@@ -301,9 +306,12 @@ ServerEnvironment::~ServerEnvironment()
301306 for (RemotePlayer *m_player : m_players) {
302307 delete m_player;
303308 }
309+ m_players.clear ();
304310
305311 delete m_player_database;
312+ m_player_database = nullptr ;
306313 delete m_auth_database;
314+ m_auth_database = nullptr ;
307315}
308316
309317Map & ServerEnvironment::getMap ()
@@ -1208,6 +1216,11 @@ void ServerEnvironment::deleteParticleSpawner(u32 id, bool remove_from_object)
12081216u16 ServerEnvironment::addActiveObject (std::unique_ptr<ServerActiveObject> object)
12091217{
12101218 assert (object); // Pre-condition
1219+ if (m_shutting_down) {
1220+ warningstream << " ServerEnvironment: refusing to add active object "
1221+ " during shutdown: " << object->getDescription () << std::endl;
1222+ return 0 ;
1223+ }
12111224 m_added_objects++;
12121225 u16 id = addActiveObjectRaw (std::move (object), nullptr , 0 );
12131226 return id;
@@ -1569,7 +1582,7 @@ std::unique_ptr<ServerActiveObject> ServerEnvironment::createSAO(ActiveObjectTyp
15691582*/
15701583void ServerEnvironment::activateObjects (MapBlock *block, u32 dtime_s)
15711584{
1572- if (block == NULL )
1585+ if (! block || m_shutting_down )
15731586 return ;
15741587
15751588 if (!block->onObjectsActivation ())
0 commit comments