From 4519469547c0f8befe74e3e80a94efb0e076ba34 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 22 Sep 2020 21:21:47 +0100 Subject: Do not call into things we don't own in destructors - Remove improper accesses in cChunk destructor * Fixes #4894 --- src/ChunkMap.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/ChunkMap.cpp') diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 71b8a7a24..53bb905a6 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -1717,10 +1717,17 @@ void cChunkMap::UnloadUnusedChunks(void) for (auto itr = m_Chunks.begin(); itr != m_Chunks.end();) { if ( - (itr->second.CanUnload()) && // Can unload + itr->second.CanUnload() && // Can unload !cPluginManager::Get()->CallHookChunkUnloading(*GetWorld(), itr->first.ChunkX, itr->first.ChunkZ) // Plugins agree ) { + // First notify plugins: + cPluginManager::Get()->CallHookChunkUnloaded(*m_World, itr->first.ChunkX, itr->first.ChunkZ); + + // Notify entities within the chunk, while everything's still valid: + itr->second.OnUnload(); + + // Kill the chunk: itr = m_Chunks.erase(itr); } else -- cgit v1.2.3