1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-10-15 22:46:36 +00:00

Don't reference a potential end iterator

This commit is contained in:
Evil Eye 2025-09-02 17:39:35 +02:00
parent 2e18809ed9
commit 3ec0812b91
2 changed files with 6 additions and 7 deletions

View file

@ -340,8 +340,8 @@ namespace MWMechanics
// invisibility manually // invisibility manually
purgeEffect(ptr, ESM::MagicEffect::Invisibility); purgeEffect(ptr, ESM::MagicEffect::Invisibility);
applyPurges(ptr); applyPurges(ptr);
ActiveSpellParams* params = initParams(ptr, ActiveSpellParams{ *slot, enchantment, ptr }, context); const bool added = initParams(ptr, ActiveSpellParams{ *slot, enchantment, ptr }, context);
if (params) if (added)
context.mUpdateSpellWindow = true; context.mUpdateSpellWindow = true;
} }
} }
@ -468,16 +468,15 @@ namespace MWMechanics
return false; return false;
} }
ActiveSpells::ActiveSpellParams* ActiveSpells::initParams( bool ActiveSpells::initParams(const MWWorld::Ptr& ptr, const ActiveSpellParams& params, UpdateContext& context)
const MWWorld::Ptr& ptr, const ActiveSpellParams& params, UpdateContext& context)
{ {
mSpells.emplace_back(params).setActiveSpellId(MWBase::Environment::get().getESMStore()->generateId()); mSpells.emplace_back(params).setActiveSpellId(MWBase::Environment::get().getESMStore()->generateId());
auto it = mSpells.end(); auto it = mSpells.end();
--it; --it;
// We instantly apply the effect with a duration of 0 so continuous effects can be purged before truly applying // 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)) if (context.mUpdate && updateActiveSpell(ptr, 0.f, it, context))
return nullptr; return false;
return &*it; return true;
} }
void ActiveSpells::addToSpells(const MWWorld::Ptr& ptr, const ActiveSpellParams& spell, UpdateContext& context) void ActiveSpells::addToSpells(const MWWorld::Ptr& ptr, const ActiveSpellParams& spell, UpdateContext& context)

View file

@ -131,7 +131,7 @@ namespace MWMechanics
bool updateActiveSpell( bool updateActiveSpell(
const MWWorld::Ptr& ptr, float duration, Collection::iterator& spellIt, UpdateContext& context); 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: public:
ActiveSpells(); ActiveSpells();