1
0

Fixed a race condition when adding a player to a world.

This commit is contained in:
madmaxoft
2014-06-10 18:25:53 +02:00
parent 6c43799cc5
commit 366ecf9dfd
3 changed files with 29 additions and 4 deletions

View File

@@ -1665,6 +1665,30 @@ void cChunkMap::AddEntity(cEntity * a_Entity)
void cChunkMap::AddEntityIfNotPresent(cEntity * a_Entity)
{
cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_Entity->GetChunkX(), ZERO_CHUNK_Y, a_Entity->GetChunkZ());
if (
(Chunk == NULL) || // Chunk not present at all
(!Chunk->IsValid() && !a_Entity->IsPlayer()) // Chunk present, but no valid data; players need to spawn in such chunks (#953)
)
{
LOGWARNING("Entity at %p (%s, ID %d) spawning in a non-existent chunk, the entity is lost.",
a_Entity, a_Entity->GetClass(), a_Entity->GetUniqueID()
);
return;
}
if (!Chunk->HasEntity(a_Entity->GetUniqueID()))
{
Chunk->AddEntity(a_Entity);
}
}
bool cChunkMap::HasEntity(int a_UniqueID)
{
cCSLock Lock(m_CSLayers);