From 16aeb84cd35996a6b41f10cbc48a677eeccc911c Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 2 Jan 2021 13:50:34 +0000 Subject: Fix potential destruction crashes (#5095) * Fix potential destruction crashes * Fix destructors accessing destroyted objects * Fix cPlayer not destroying windows (Destroyed never called) * Tentatively fixes #4608, fixes #3236, fixes #3262 - Remove cEntity::Destroyed() and replace with cEntity::OnRemoveFromWorld() * Add missing call to OnRemoveFromWorld --- src/BlockEntities/BrewingstandEntity.cpp | 44 ++++++++++---------------------- 1 file changed, 14 insertions(+), 30 deletions(-) (limited to 'src/BlockEntities/BrewingstandEntity.cpp') diff --git a/src/BlockEntities/BrewingstandEntity.cpp b/src/BlockEntities/BrewingstandEntity.cpp index 9c43f257f..44a077bc0 100644 --- a/src/BlockEntities/BrewingstandEntity.cpp +++ b/src/BlockEntities/BrewingstandEntity.cpp @@ -13,7 +13,6 @@ cBrewingstandEntity::cBrewingstandEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld * a_World): Super(a_BlockType, a_BlockMeta, a_Pos, ContentsWidth, ContentsHeight, a_World), - m_IsDestroyed(false), m_IsBrewing(false), m_TimeBrewed(0), m_RemainingFuel(0) @@ -25,30 +24,6 @@ cBrewingstandEntity::cBrewingstandEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_Blo -cBrewingstandEntity::~cBrewingstandEntity() -{ - // Tell window its owner is destroyed - cWindow * Window = GetWindow(); - if (Window != nullptr) - { - Window->OwnerDestroyed(); - } -} - - - - - -void cBrewingstandEntity::Destroy() -{ - m_IsDestroyed = true; - Super::Destroy(); -} - - - - - void cBrewingstandEntity::CopyFrom(const cBlockEntity & a_Src) { Super::CopyFrom(a_Src); @@ -70,6 +45,20 @@ void cBrewingstandEntity::CopyFrom(const cBlockEntity & a_Src) +void cBrewingstandEntity::OnRemoveFromWorld() +{ + const auto Window = GetWindow(); + if (Window != nullptr) + { + // Tell window its owner is destroyed: + Window->OwnerDestroyed(); + } +} + + + + + void cBrewingstandEntity::SendTo(cClientHandle & a_Client) { // Nothing needs to be sent @@ -206,11 +195,6 @@ void cBrewingstandEntity::OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum) { Super::OnSlotChanged(a_ItemGrid, a_SlotNum); - if (m_IsDestroyed) - { - return; - } - ASSERT(a_ItemGrid == &m_Contents); // Check for fuel -- cgit v1.2.3