Merge pull request #3478 from cuberite/FixBadChunkCoordsLoad
Fixed minecart destruction using deallocated memory.
This commit is contained in:
commit
fc40932ab1
@ -1250,10 +1250,15 @@ void cMinecartWithChest::Destroyed()
|
|||||||
m_Contents.CopyToItems(Pickups);
|
m_Contents.CopyToItems(Pickups);
|
||||||
|
|
||||||
|
|
||||||
// This makes the command not execute if the world is in the midst of destruction :)
|
// Schedule the pickups creation for the next world tick
|
||||||
GetWorld()->ScheduleTask(1, [this, Pickups](cWorld & World)
|
// This avoids a deadlock when terminating the world
|
||||||
|
// Note that the scheduled task may be run when this object is no longer valid, we need to store everything in the task's captured variables
|
||||||
|
auto posX = GetPosX();
|
||||||
|
auto posY = GetPosY() + 1;
|
||||||
|
auto posZ = GetPosZ();
|
||||||
|
GetWorld()->ScheduleTask(1, [Pickups, posX, posY, posZ](cWorld & World)
|
||||||
{
|
{
|
||||||
World.SpawnItemPickups(Pickups, GetPosX(), GetPosY() + 1, GetPosZ(), 4);
|
World.SpawnItemPickups(Pickups, posX, posY, posZ, 4);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,6 +142,8 @@ size_t cWorldStorage::GetSaveQueueLength(void)
|
|||||||
|
|
||||||
void cWorldStorage::QueueLoadChunk(int a_ChunkX, int a_ChunkZ, cChunkCoordCallback * a_Callback)
|
void cWorldStorage::QueueLoadChunk(int a_ChunkX, int a_ChunkZ, cChunkCoordCallback * a_Callback)
|
||||||
{
|
{
|
||||||
|
ASSERT((a_ChunkX > -0x08000000) && (a_ChunkX < 0x08000000));
|
||||||
|
ASSERT((a_ChunkZ > -0x08000000) && (a_ChunkZ < 0x08000000));
|
||||||
ASSERT(m_World->IsChunkQueued(a_ChunkX, a_ChunkZ));
|
ASSERT(m_World->IsChunkQueued(a_ChunkX, a_ChunkZ));
|
||||||
|
|
||||||
m_LoadQueue.EnqueueItem(cChunkCoordsWithCallback(a_ChunkX, a_ChunkZ, a_Callback));
|
m_LoadQueue.EnqueueItem(cChunkCoordsWithCallback(a_ChunkX, a_ChunkZ, a_Callback));
|
||||||
|
Loading…
Reference in New Issue
Block a user