From a4503ddb777f61799971e4a7f9711dbbda5bc7fd Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Tue, 28 Feb 2012 14:58:07 +0000 Subject: Setting the m_bDestroyed flag only after the cClienthandle is truly destroyed; cClientHandle's destructor now locks loaded chunk lists git-svn-id: http://mc-server.googlecode.com/svn/trunk@340 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cClientHandle.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp index 4a6a0b508..7128b925c 100644 --- a/source/cClientHandle.cpp +++ b/source/cClientHandle.cpp @@ -148,8 +148,11 @@ cClientHandle::~cClientHandle() // Remove from cSocketThreads, we're not to be called anymore: cRoot::Get()->GetServer()->ClientDestroying(this); - m_LoadedChunks.clear(); - m_ChunksToSend.clear(); + { + cCSLock Lock(m_CSChunkLists); + m_LoadedChunks.clear(); + m_ChunksToSend.clear(); + } if (m_Player != NULL) { @@ -226,12 +229,16 @@ cClientHandle::~cClientHandle() void cClientHandle::Destroy() { - m_bDestroyed = true; + // Setting m_bDestroyed was moved to the bottom of Destroy(), + // otherwise the destructor may be called within another thread before the client is removed from chunks + // http://forum.mc-server.org/showthread.php?tid=366 if ((m_Player != NULL) && (m_Player->GetWorld() != NULL)) { RemoveFromAllChunks(); } + + m_bDestroyed = true; } -- cgit v1.2.3