Fix crash when onPcEquip script removes the equipped item (Fixes #3016)

This commit is contained in:
scrawl 2015-11-24 22:50:54 +01:00
parent 1b77428c59
commit edfcb45ad7
2 changed files with 15 additions and 8 deletions

View file

@ -471,16 +471,18 @@ namespace MWGui
MWBase::Environment::get().getScriptManager()->run (script, interpreterContext); MWBase::Environment::get().getScriptManager()->run (script, interpreterContext);
} }
mSkippedToEquip = MWWorld::Ptr();
if (ptr.getRefData().getCount()) // make sure the item is still there, the script might have removed it
{
if (script.empty() || ptr.getRefData().getLocals().getIntVar(script, "pcskipequip") == 0) if (script.empty() || ptr.getRefData().getLocals().getIntVar(script, "pcskipequip") == 0)
{ {
boost::shared_ptr<MWWorld::Action> action = ptr.getClass().use(ptr); boost::shared_ptr<MWWorld::Action> action = ptr.getClass().use(ptr);
action->execute (player); action->execute (player);
mSkippedToEquip = MWWorld::Ptr();
} }
else else
mSkippedToEquip = ptr; mSkippedToEquip = ptr;
}
if (isVisible()) if (isVisible())
{ {

View file

@ -52,7 +52,12 @@ namespace MWWorld
} }
} }
assert(it != invStore.end()); if (it == invStore.end())
{
std::stringstream error;
error << "ActionEquip can't find item " << object.getCellRef().getRefId();
throw std::runtime_error(error.str());
}
// equip the item in the first free slot // equip the item in the first free slot
std::vector<int>::const_iterator slot=slots_.first.begin(); std::vector<int>::const_iterator slot=slots_.first.begin();