On zone shutdown purge all spells pending to be deleted so we do not reference dead spell->zone ptr

This commit is contained in:
Emagi 2025-08-08 14:40:30 -04:00
parent 480086d85d
commit 4d0ef974ae
3 changed files with 4 additions and 3 deletions

View File

@ -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<LuaSpell*> tmp_deletes;
vector<LuaSpell*>::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;

View File

@ -520,7 +520,7 @@ public:
map<Client*, int32> 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);

View File

@ -190,6 +190,7 @@ ZoneServer::ZoneServer(const char* name) {
typedef map <int32, bool> 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) {