cWorld Threads: Seperate initialization and thread start.
Prevents nullptr dereferences before Start has been called.
This commit is contained in:
@@ -88,9 +88,9 @@ public:
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// cLightingThread:
|
||||
|
||||
cLightingThread::cLightingThread(void) :
|
||||
cLightingThread::cLightingThread(cWorld & a_World):
|
||||
super("cLightingThread"),
|
||||
m_World(nullptr),
|
||||
m_World(a_World),
|
||||
m_MaxHeight(0),
|
||||
m_NumSeeds(0)
|
||||
{
|
||||
@@ -109,18 +109,6 @@ cLightingThread::~cLightingThread()
|
||||
|
||||
|
||||
|
||||
bool cLightingThread::Start(cWorld * a_World)
|
||||
{
|
||||
ASSERT(m_World == nullptr); // Not started yet
|
||||
m_World = a_World;
|
||||
|
||||
return super::Start();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cLightingThread::Stop(void)
|
||||
{
|
||||
{
|
||||
@@ -150,8 +138,6 @@ void cLightingThread::Stop(void)
|
||||
|
||||
void cLightingThread::QueueChunk(int a_ChunkX, int a_ChunkZ, std::unique_ptr<cChunkCoordCallback> a_CallbackAfter)
|
||||
{
|
||||
ASSERT(m_World != nullptr); // Did you call Start() properly?
|
||||
|
||||
cChunkStay * ChunkStay = new cLightingChunkStay(*this, a_ChunkX, a_ChunkZ, std::move(a_CallbackAfter));
|
||||
{
|
||||
// The ChunkStay will enqueue itself using the QueueChunkStay() once it is fully loaded
|
||||
@@ -159,7 +145,7 @@ void cLightingThread::QueueChunk(int a_ChunkX, int a_ChunkZ, std::unique_ptr<cCh
|
||||
cCSLock Lock(m_CS);
|
||||
m_PendingQueue.push_back(ChunkStay);
|
||||
}
|
||||
ChunkStay->Enable(*m_World->GetChunkMap());
|
||||
ChunkStay->Enable(*m_World.GetChunkMap());
|
||||
}
|
||||
|
||||
|
||||
@@ -238,7 +224,7 @@ void cLightingThread::Execute(void)
|
||||
void cLightingThread::LightChunk(cLightingChunkStay & a_Item)
|
||||
{
|
||||
// If the chunk is already lit, skip it (report as success):
|
||||
if (m_World->IsChunkLighted(a_Item.m_ChunkX, a_Item.m_ChunkZ))
|
||||
if (m_World.IsChunkLighted(a_Item.m_ChunkX, a_Item.m_ChunkZ))
|
||||
{
|
||||
if (a_Item.m_CallbackAfter != nullptr)
|
||||
{
|
||||
@@ -319,7 +305,7 @@ void cLightingThread::LightChunk(cLightingChunkStay & a_Item)
|
||||
CompressLight(m_BlockLight, BlockLight);
|
||||
CompressLight(m_SkyLight, SkyLight);
|
||||
|
||||
m_World->ChunkLighted(a_Item.m_ChunkX, a_Item.m_ChunkZ, BlockLight, SkyLight);
|
||||
m_World.ChunkLighted(a_Item.m_ChunkX, a_Item.m_ChunkZ, BlockLight, SkyLight);
|
||||
|
||||
if (a_Item.m_CallbackAfter != nullptr)
|
||||
{
|
||||
@@ -341,7 +327,7 @@ void cLightingThread::ReadChunks(int a_ChunkX, int a_ChunkZ)
|
||||
for (int x = 0; x < 3; x++)
|
||||
{
|
||||
Reader.m_ReadingChunkX = x;
|
||||
VERIFY(m_World->GetChunkData(a_ChunkX + x - 1, a_ChunkZ + z - 1, Reader));
|
||||
VERIFY(m_World.GetChunkData(a_ChunkX + x - 1, a_ChunkZ + z - 1, Reader));
|
||||
} // for z
|
||||
} // for x
|
||||
|
||||
|
||||
Reference in New Issue
Block a user