1
0

Fixed crashes in world's clientlist manipulators

This commit is contained in:
madmaxoft 2013-08-14 13:43:55 +02:00
parent 8c3837987b
commit f8757d3606
2 changed files with 28 additions and 2 deletions

View File

@ -817,6 +817,26 @@ void cWorld::TickClients(float a_Dt)
cClientHandleList RemoveClients;
{
cCSLock Lock(m_CSClients);
// Remove clients scheduled for removal:
for (cClientHandleList::iterator itr = m_ClientsToRemove.begin(), end = m_ClientsToRemove.end(); itr != end; ++itr)
{
m_Clients.remove(*itr);
} // for itr - m_ClientsToRemove[]
m_ClientsToRemove.clear();
// Add clients scheduled for adding:
for (cClientHandleList::iterator itr = m_ClientsToAdd.begin(), end = m_ClientsToAdd.end(); itr != end; ++itr)
{
if (std::find(m_Clients.begin(), m_Clients.end(), *itr) != m_Clients.end())
{
ASSERT(!"Adding a client that is already in the clientlist");
continue;
}
m_Clients.push_back(*itr);
} // for itr - m_ClientsToRemove[]
m_ClientsToAdd.clear();
// Tick the clients, take out those that have been destroyed into RemoveClients
for (cClientHandleList::iterator itr = m_Clients.begin(); itr != m_Clients.end();)
{
@ -2018,7 +2038,7 @@ void cWorld::AddPlayer(cPlayer * a_Player)
if (a_Player->GetClientHandle() != NULL)
{
cCSLock Lock(m_CSClients);
m_Clients.push_back(a_Player->GetClientHandle());
m_ClientsToAdd.push_back(a_Player->GetClientHandle());
}
// The player has already been added to the chunkmap as the entity, do NOT add again!
@ -2040,7 +2060,7 @@ void cWorld::RemovePlayer(cPlayer * a_Player)
if (a_Player->GetClientHandle() != NULL)
{
cCSLock Lock(m_CSClients);
m_Clients.remove(a_Player->GetClientHandle());
m_ClientsToRemove.push_back(a_Player->GetClientHandle());
}
}

View File

@ -666,6 +666,12 @@ private:
/// List of clients in this world, these will be ticked by this world
cClientHandleList m_Clients;
/// Clients that are scheduled for removal (ticked in another world), waiting for TickClients() to remove them
cClientHandleList m_ClientsToRemove;
/// Clients that are scheduled for adding, waiting for TickClients to add them
cClientHandleList m_ClientsToAdd;
cWorld(const AString & a_WorldName);