From 79bc6e73ff38bf33e8304c72d1843ba5d7b9c918 Mon Sep 17 00:00:00 2001 From: David Markowitz Date: Tue, 2 Jan 2024 18:21:33 -0800 Subject: [PATCH] crash and log fix --- dCommon/Logger.cpp | 2 +- dGame/dComponents/BuffComponent.cpp | 12 +++++++++--- dGame/dComponents/BuffComponent.h | 3 +++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/dCommon/Logger.cpp b/dCommon/Logger.cpp index b4181205..1888f1eb 100644 --- a/dCommon/Logger.cpp +++ b/dCommon/Logger.cpp @@ -16,7 +16,7 @@ Writer::~Writer() { } void Writer::Log(const char* time, const char* message) { - if (!m_Outfile) return; + if (!m_Outfile || !m_Enabled) return; fputs(time, m_Outfile); fputs(message, m_Outfile); diff --git a/dGame/dComponents/BuffComponent.cpp b/dGame/dComponents/BuffComponent.cpp index 32d7d1d4..1819438b 100644 --- a/dGame/dComponents/BuffComponent.cpp +++ b/dGame/dComponents/BuffComponent.cpp @@ -95,10 +95,16 @@ void BuffComponent::Update(float deltaTime) { if (buff.second.time <= 0.0f) { RemoveBuff(buff.first); - - break; } } + + if (m_BuffsToRemove.empty()) return; + + for (const auto& buff : m_BuffsToRemove) { + m_Buffs.erase(buff); + } + + m_BuffsToRemove.clear(); } const std::string& GetFxName(const std::string& buffname) { @@ -216,7 +222,7 @@ void BuffComponent::RemoveBuff(int32_t id, bool fromUnEquip, bool removeImmunity GameMessages::SendRemoveBuff(m_Parent, fromUnEquip, removeImmunity, id); - m_Buffs.erase(iter); + m_BuffsToRemove.push_back(id); RemoveBuffEffect(id); } diff --git a/dGame/dComponents/BuffComponent.h b/dGame/dComponents/BuffComponent.h index 7187f8f7..7f7b44d8 100644 --- a/dGame/dComponents/BuffComponent.h +++ b/dGame/dComponents/BuffComponent.h @@ -140,6 +140,9 @@ private: */ std::map m_Buffs; + // Buffs to remove at the end of the update frame. + std::vector m_BuffsToRemove; + /** * Parameters (=effects) for each buff */