cWorld: Add entities without holding of m_CSEntitiesToAdd
* Fixes deadlock when cWorld::AddEntity is called while holding chunk map CS.
This commit is contained in:
parent
a5869b3c09
commit
1779db1201
@ -995,9 +995,13 @@ void cWorld::Tick(std::chrono::milliseconds a_Dt, std::chrono::milliseconds a_La
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add entities waiting in the queue to be added:
|
// Add entities waiting in the queue to be added:
|
||||||
|
cEntityList EntitiesToAdd;
|
||||||
{
|
{
|
||||||
|
// Don't access chunkmap while holding lock
|
||||||
cCSLock Lock(m_CSEntitiesToAdd);
|
cCSLock Lock(m_CSEntitiesToAdd);
|
||||||
for (auto & Entity : m_EntitiesToAdd)
|
std::swap(EntitiesToAdd, m_EntitiesToAdd);
|
||||||
|
}
|
||||||
|
for (auto & Entity : EntitiesToAdd)
|
||||||
{
|
{
|
||||||
Entity->SetWorld(this);
|
Entity->SetWorld(this);
|
||||||
auto EntityPtr = Entity.get();
|
auto EntityPtr = Entity.get();
|
||||||
@ -1005,8 +1009,7 @@ void cWorld::Tick(std::chrono::milliseconds a_Dt, std::chrono::milliseconds a_La
|
|||||||
ASSERT(!EntityPtr->IsTicking());
|
ASSERT(!EntityPtr->IsTicking());
|
||||||
EntityPtr->SetIsTicking(true);
|
EntityPtr->SetIsTicking(true);
|
||||||
}
|
}
|
||||||
m_EntitiesToAdd.clear();
|
EntitiesToAdd.clear();
|
||||||
}
|
|
||||||
|
|
||||||
// Add players waiting in the queue to be added:
|
// Add players waiting in the queue to be added:
|
||||||
AddQueuedPlayers();
|
AddQueuedPlayers();
|
||||||
|
Loading…
Reference in New Issue
Block a user