From 3ec0812b913f992f1d06709c5dcb534dfb187886 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Tue, 2 Sep 2025 17:39:35 +0200 Subject: [PATCH] Don't reference a potential end iterator --- apps/openmw/mwmechanics/activespells.cpp | 11 +++++------ apps/openmw/mwmechanics/activespells.hpp | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwmechanics/activespells.cpp b/apps/openmw/mwmechanics/activespells.cpp index 24e43e6d27..78d335738c 100644 --- a/apps/openmw/mwmechanics/activespells.cpp +++ b/apps/openmw/mwmechanics/activespells.cpp @@ -340,8 +340,8 @@ namespace MWMechanics // invisibility manually purgeEffect(ptr, ESM::MagicEffect::Invisibility); applyPurges(ptr); - ActiveSpellParams* params = initParams(ptr, ActiveSpellParams{ *slot, enchantment, ptr }, context); - if (params) + const bool added = initParams(ptr, ActiveSpellParams{ *slot, enchantment, ptr }, context); + if (added) context.mUpdateSpellWindow = true; } } @@ -468,16 +468,15 @@ namespace MWMechanics return false; } - ActiveSpells::ActiveSpellParams* ActiveSpells::initParams( - const MWWorld::Ptr& ptr, const ActiveSpellParams& params, UpdateContext& context) + bool ActiveSpells::initParams(const MWWorld::Ptr& ptr, const ActiveSpellParams& params, UpdateContext& context) { mSpells.emplace_back(params).setActiveSpellId(MWBase::Environment::get().getESMStore()->generateId()); auto it = mSpells.end(); --it; // We instantly apply the effect with a duration of 0 so continuous effects can be purged before truly applying if (context.mUpdate && updateActiveSpell(ptr, 0.f, it, context)) - return nullptr; - return &*it; + return false; + return true; } void ActiveSpells::addToSpells(const MWWorld::Ptr& ptr, const ActiveSpellParams& spell, UpdateContext& context) diff --git a/apps/openmw/mwmechanics/activespells.hpp b/apps/openmw/mwmechanics/activespells.hpp index 465e5aa456..32046256fd 100644 --- a/apps/openmw/mwmechanics/activespells.hpp +++ b/apps/openmw/mwmechanics/activespells.hpp @@ -131,7 +131,7 @@ namespace MWMechanics bool updateActiveSpell( const MWWorld::Ptr& ptr, float duration, Collection::iterator& spellIt, UpdateContext& context); - ActiveSpellParams* initParams(const MWWorld::Ptr& ptr, const ActiveSpellParams& params, UpdateContext& context); + bool initParams(const MWWorld::Ptr& ptr, const ActiveSpellParams& params, UpdateContext& context); public: ActiveSpells();