Merge branch 'derefkarstaag' into 'master'

Don't dereference a potential end iterator

See merge request OpenMW/openmw!4912
This commit is contained in:
Alexei Kotov 2025-09-03 19:13:23 +03:00
commit 975e8d7412
2 changed files with 6 additions and 7 deletions

View File

@ -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)

View File

@ -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();