1
0
Fork 0

Entities can fail to add into a chunk

- MoveEntityToNewChunk, AddEntity can fail. Ensure we handle these cases correctly
This commit is contained in:
Tiger Wang 2020-08-29 21:34:21 +01:00
parent 07ffd9f6f3
commit f84e805453
3 changed files with 10 additions and 11 deletions

View File

@ -892,7 +892,17 @@ void cChunkMap::AddEntity(OwnedEntity a_Entity)
);
return;
}
const auto EntityPtr = a_Entity.get();
ASSERT(EntityPtr->GetWorld() == m_World);
Chunk->AddEntity(std::move(a_Entity));
EntityPtr->OnAddToWorld(*m_World);
ASSERT(!EntityPtr->IsTicking());
EntityPtr->SetIsTicking(true);
cPluginManager::Get()->CallHookSpawnedEntity(*m_World, *EntityPtr);
}

View File

@ -82,11 +82,6 @@ cEntity::cEntity(eEntityType a_EntityType, Vector3d a_Pos, double a_Width, doubl
cEntity::~cEntity()
{
// Before deleting, the entity needs to have been removed from the world, if ever added
ASSERT((m_World == nullptr) || !m_World->HasEntity(m_UniqueID));
ASSERT(!IsTicking());
/*
// DEBUG:
FLOGD("Deleting entity {0} at pos {1:.2f} ~ [{2}, {3}]; ptr {4}",

View File

@ -1023,13 +1023,7 @@ void cWorld::Tick(std::chrono::milliseconds a_Dt, std::chrono::milliseconds a_La
}
for (auto & Entity : EntitiesToAdd)
{
auto EntityPtr = Entity.get();
ASSERT(EntityPtr->GetWorld() == this);
m_ChunkMap->AddEntity(std::move(Entity));
EntityPtr->OnAddToWorld(*this);
ASSERT(!EntityPtr->IsTicking());
EntityPtr->SetIsTicking(true);
cPluginManager::Get()->CallHookSpawnedEntity(*this, *Entity);
}
EntitiesToAdd.clear();