From 870c6585004f4f51507a829c291ce88b2c360162 Mon Sep 17 00:00:00 2001 From: scrawl <720642+scrawl@users.noreply.github.com> Date: Thu, 8 Mar 2018 23:38:04 +0000 Subject: [PATCH] Remove missing souls, remove some runaway exceptions (Fixes #4111) --- apps/openmw/mwclass/misc.cpp | 12 +++++++----- apps/openmw/mwgui/sortfilteritemmodel.cpp | 2 +- apps/openmw/mwmechanics/enchanting.cpp | 7 +++++-- apps/openmw/mwworld/livecellref.cpp | 6 ++++++ 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/apps/openmw/mwclass/misc.cpp b/apps/openmw/mwclass/misc.cpp index a68176226..5a933d535 100644 --- a/apps/openmw/mwclass/misc.cpp +++ b/apps/openmw/mwclass/misc.cpp @@ -83,8 +83,9 @@ namespace MWClass if (ptr.getCellRef().getSoul() != "") { - const ESM::Creature *creature = MWBase::Environment::get().getWorld()->getStore().get().find(ref->mRef.getSoul()); - value *= creature->mData.mSoul; + const ESM::Creature *creature = MWBase::Environment::get().getWorld()->getStore().get().search(ref->mRef.getSoul()); + if (creature) + value *= creature->mData.mSoul; } return value; @@ -148,8 +149,9 @@ namespace MWClass if (ref->mRef.getSoul() != "") { - const ESM::Creature *creature = store.get().find(ref->mRef.getSoul()); - info.caption += " (" + creature->mName + ")"; + const ESM::Creature *creature = store.get().search(ref->mRef.getSoul()); + if (creature) + info.caption += " (" + creature->mName + ")"; } std::string text; @@ -210,7 +212,7 @@ namespace MWClass std::shared_ptr Miscellaneous::use (const MWWorld::Ptr& ptr) const { - if (ptr.getCellRef().getSoul().empty()) + if (ptr.getCellRef().getSoul().empty() || !MWBase::Environment::get().getWorld()->getStore().get().search(ptr.getCellRef().getSoul())) return std::shared_ptr(new MWWorld::NullAction()); else return std::shared_ptr(new MWWorld::ActionSoulgem(ptr)); diff --git a/apps/openmw/mwgui/sortfilteritemmodel.cpp b/apps/openmw/mwgui/sortfilteritemmodel.cpp index 1ee3cf631..097412b5d 100644 --- a/apps/openmw/mwgui/sortfilteritemmodel.cpp +++ b/apps/openmw/mwgui/sortfilteritemmodel.cpp @@ -208,7 +208,7 @@ namespace MWGui if ((mFilter & Filter_OnlyEnchanted) && !(item.mFlags & ItemStack::Flag_Enchanted)) return false; if ((mFilter & Filter_OnlyChargedSoulstones) && (base.getTypeName() != typeid(ESM::Miscellaneous).name() - || base.getCellRef().getSoul() == "")) + || base.getCellRef().getSoul() == "" || !MWBase::Environment::get().getWorld()->getStore().get().search(base.getCellRef().getSoul()))) return false; if ((mFilter & Filter_OnlyRepairTools) && (base.getTypeName() != typeid(ESM::Repair).name())) return false; diff --git a/apps/openmw/mwmechanics/enchanting.cpp b/apps/openmw/mwmechanics/enchanting.cpp index a658c379a..08f30aba1 100644 --- a/apps/openmw/mwmechanics/enchanting.cpp +++ b/apps/openmw/mwmechanics/enchanting.cpp @@ -242,8 +242,11 @@ namespace MWMechanics return 0; if(mSoulGemPtr.getCellRef().getSoul()=="") return 0; - const ESM::Creature* soul = store.get().find(mSoulGemPtr.getCellRef().getSoul()); - return soul->mData.mSoul; + const ESM::Creature* soul = store.get().search(mSoulGemPtr.getCellRef().getSoul()); + if(soul) + return soul->mData.mSoul; + else + return 0; } int Enchanting::getMaxEnchantValue() const diff --git a/apps/openmw/mwworld/livecellref.cpp b/apps/openmw/mwworld/livecellref.cpp index 294734f46..b8178f774 100644 --- a/apps/openmw/mwworld/livecellref.cpp +++ b/apps/openmw/mwworld/livecellref.cpp @@ -48,6 +48,12 @@ void MWWorld::LiveCellRefBase::loadImp (const ESM::ObjectState& state) } mClass->readAdditionalState (ptr, state); + + if (!mRef.getSoul().empty() && !MWBase::Environment::get().getWorld()->getStore().get().search(mRef.getSoul())) + { + std::cerr << "Soul '" << mRef.getSoul() << "' not found, removing the soul from soul gem" << std::endl; + mRef.setSoul(std::string()); + } } void MWWorld::LiveCellRefBase::saveImp (ESM::ObjectState& state) const