From caa05e7935eab20259f9bd02a278d97c04978764 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Thu, 15 Dec 2016 14:57:48 +0100 Subject: Fixed minecart destruction using deallocated memory. --- src/Entities/Minecart.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/Entities/Minecart.cpp') diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index c75c8288c..b8e8e9f29 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -1250,10 +1250,15 @@ void cMinecartWithChest::Destroyed() m_Contents.CopyToItems(Pickups); - // This makes the command not execute if the world is in the midst of destruction :) - GetWorld()->ScheduleTask(1, [this, Pickups](cWorld & World) + // Schedule the pickups creation for the next world tick + // 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); }); } -- cgit v1.2.3