From 4d0ef974ae1298a18ef739666c07e6fe6e36f8c1 Mon Sep 17 00:00:00 2001 From: Emagi Date: Fri, 8 Aug 2025 14:40:30 -0400 Subject: [PATCH] On zone shutdown purge all spells pending to be deleted so we do not reference dead spell->zone ptr --- source/WorldServer/LuaInterface.cpp | 4 ++-- source/WorldServer/LuaInterface.h | 2 +- source/WorldServer/zoneserver.cpp | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/source/WorldServer/LuaInterface.cpp b/source/WorldServer/LuaInterface.cpp index 62df51f..8a88094 100644 --- a/source/WorldServer/LuaInterface.cpp +++ b/source/WorldServer/LuaInterface.cpp @@ -1867,7 +1867,7 @@ void LuaInterface::AddUserDataPtr(LUAUserData* data, void* data_ptr) { user_data[data] = Timer::GetCurrentTime2() + 300000; //allow a function to use this pointer for 5 minutes } -void LuaInterface::DeletePendingSpells(bool all) { +void LuaInterface::DeletePendingSpells(bool all, ZoneServer* zone) { MSpells.lock(); MSpellDelete.lock(); if (spells_pending_delete.size() > 0) { @@ -1876,7 +1876,7 @@ void LuaInterface::DeletePendingSpells(bool all) { vector tmp_deletes; vector::iterator del_itr; for (itr = spells_pending_delete.begin(); itr != spells_pending_delete.end(); itr++) { - if (all || time >= itr->second) + if ((!zone && (all || time >= itr->second)) || (zone && itr->first->zone == zone)) tmp_deletes.push_back(itr->first); } LuaSpell* spell = 0; diff --git a/source/WorldServer/LuaInterface.h b/source/WorldServer/LuaInterface.h index 032e20a..e3999f9 100644 --- a/source/WorldServer/LuaInterface.h +++ b/source/WorldServer/LuaInterface.h @@ -520,7 +520,7 @@ public: map GetDebugClients(){ return debug_clients; } void AddUserDataPtr(LUAUserData* data, void* data_ptr = 0); void DeleteUserDataPtrs(bool all); - void DeletePendingSpells(bool all); + void DeletePendingSpells(bool all, ZoneServer* zone = nullptr); void DeletePendingSpell(LuaSpell* spell); Mutex* GetSpawnScriptMutex(const char* name); Mutex* GetItemScriptMutex(const char* name); diff --git a/source/WorldServer/zoneserver.cpp b/source/WorldServer/zoneserver.cpp index 05b14ee..86bc186 100644 --- a/source/WorldServer/zoneserver.cpp +++ b/source/WorldServer/zoneserver.cpp @@ -190,6 +190,7 @@ ZoneServer::ZoneServer(const char* name) { typedef map ChangedSpawnMapType; ZoneServer::~ZoneServer() { + lua_interface->DeletePendingSpells(true, this); zoneShuttingDown = true; //ensure other threads shut down too //allow other threads to properly shut down if(is_initialized) {