From 64778c6a397e08c2bfd20b6c3a7e54344a6e4a4b Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 11 Apr 2021 23:10:25 +0100 Subject: Fix improper destruction of BEs on /regen --- src/Chunk.cpp | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index b16646d5a..aa2a2887c 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -253,9 +253,9 @@ void cChunk::OnUnload() } // Notify all block entities of imminent unload: - for (auto & BlockEntity : m_BlockEntities) + for (auto & KeyPair : m_BlockEntities) { - BlockEntity.second->OnRemoveFromWorld(); + KeyPair.second->OnRemoveFromWorld(); } } @@ -362,19 +362,26 @@ void cChunk::SetAllData(SetChunkData && a_SetChunkData) Entity->SetIsTicking(true); } - // Clear the block entities present - either the loader / saver has better, or we'll create empty ones: + // Remove the block entities present - either the loader / saver has better, or we'll create empty ones: + for (auto & KeyPair : m_BlockEntities) + { + KeyPair.second->Destroy(); + KeyPair.second->OnRemoveFromWorld(); + } + + // Clear the old ones: m_BlockEntities = std::move(a_SetChunkData.BlockEntities); // Check that all block entities have a valid blocktype at their respective coords (DEBUG-mode only): - #ifndef NDEBUG - for (auto & KeyPair : m_BlockEntities) - { - cBlockEntity * Block = KeyPair.second.get(); - BLOCKTYPE EntityBlockType = Block->GetBlockType(); - BLOCKTYPE WorldBlockType = GetBlock(Block->GetRelX(), Block->GetPosY(), Block->GetRelZ()); - ASSERT(WorldBlockType == EntityBlockType); - } // for KeyPair - m_BlockEntities - #endif // !NDEBUG +#ifndef NDEBUG + for (auto & KeyPair : m_BlockEntities) + { + cBlockEntity * Block = KeyPair.second.get(); + BLOCKTYPE EntityBlockType = Block->GetBlockType(); + BLOCKTYPE WorldBlockType = GetBlock(Block->GetRelX(), Block->GetPosY(), Block->GetRelZ()); + ASSERT(WorldBlockType == EntityBlockType); + } +#endif // Set all block entities' World variable: for (auto & KeyPair : m_BlockEntities) -- cgit v1.2.3