From 14165352f6734541a2a73d0070dabbe1564bbec2 Mon Sep 17 00:00:00 2001 From: Internecine Date: Mon, 1 Aug 2016 13:16:42 +1200 Subject: [PATCH 1/2] Added exception handlers when trying to retreive enchantment and magic effect data. --- apps/openmw/mwgui/tooltips.cpp | 28 +++++++++++++++++----------- apps/openmw/mwrender/animation.cpp | 22 ++++++++++++++++++++-- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index cb3d0d0a1..2c540807d 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -395,15 +395,22 @@ namespace MWGui const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); if (info.enchant != "") { - enchant = store.get().find(info.enchant); - if (enchant->mData.mType == ESM::Enchantment::CastOnce) - text += "\n#{sItemCastOnce}"; - else if (enchant->mData.mType == ESM::Enchantment::WhenStrikes) - text += "\n#{sItemCastWhenStrikes}"; - else if (enchant->mData.mType == ESM::Enchantment::WhenUsed) - text += "\n#{sItemCastWhenUsed}"; - else if (enchant->mData.mType == ESM::Enchantment::ConstantEffect) - text += "\n#{sItemCastConstant}"; + try + { + enchant = store.get().find(info.enchant); + if (enchant->mData.mType == ESM::Enchantment::CastOnce) + text += "\n#{sItemCastOnce}"; + else if (enchant->mData.mType == ESM::Enchantment::WhenStrikes) + text += "\n#{sItemCastWhenStrikes}"; + else if (enchant->mData.mType == ESM::Enchantment::WhenUsed) + text += "\n#{sItemCastWhenUsed}"; + else if (enchant->mData.mType == ESM::Enchantment::ConstantEffect) + text += "\n#{sItemCastConstant}"; + } + catch (const std::runtime_error& ex) + { + + } } // this the maximum width of the tooltip before it starts word-wrapping @@ -472,9 +479,8 @@ namespace MWGui totalSize.width = std::max(totalSize.width, coord.width); } - if (info.enchant != "") + if (enchant) { - assert(enchant); MyGUI::Widget* enchantArea = mDynamicToolTipBox->createWidget("", MyGUI::IntCoord(padding.left, totalSize.height, 300-padding.left, 300-totalSize.height), MyGUI::Align::Stretch); diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index ddff61ac7..032fc0a35 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -1143,10 +1143,28 @@ namespace MWRender std::string enchantmentName = item.getClass().getEnchantment(item); if (enchantmentName.empty()) return result; - const ESM::Enchantment* enchantment = MWBase::Environment::get().getWorld()->getStore().get().find(enchantmentName); + + const ESM::Enchantment* enchantment = NULL; + try + { + enchantment = MWBase::Environment::get().getWorld()->getStore().get().find(enchantmentName); + } + catch (const std::runtime_error& ex) + { + return result; + } assert (enchantment->mEffects.mList.size()); - const ESM::MagicEffect* magicEffect = MWBase::Environment::get().getWorld()->getStore().get().find( + + const ESM::MagicEffect* magicEffect = NULL; + try + { + magicEffect = MWBase::Environment::get().getWorld()->getStore().get().find( enchantment->mEffects.mList.front().mEffectID); + } + catch (const std::runtime_error& ex) + { + return result; + } result.x() = magicEffect->mData.mRed / 255.f; result.y() = magicEffect->mData.mGreen / 255.f; result.z() = magicEffect->mData.mBlue / 255.f; From 90735d226d0766ea6b698d016510265765e9dc2a Mon Sep 17 00:00:00 2001 From: Internecine Date: Tue, 2 Aug 2016 11:43:41 +1200 Subject: [PATCH 2/2] Replaced Store::find usage with Store::search to remove exception handlers. --- apps/openmw/mwgui/tooltips.cpp | 8 ++------ apps/openmw/mwrender/animation.cpp | 22 ++++++---------------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index 2c540807d..9e26cb0f9 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -395,9 +395,9 @@ namespace MWGui const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); if (info.enchant != "") { - try + enchant = store.get().search(info.enchant); + if (enchant) { - enchant = store.get().find(info.enchant); if (enchant->mData.mType == ESM::Enchantment::CastOnce) text += "\n#{sItemCastOnce}"; else if (enchant->mData.mType == ESM::Enchantment::WhenStrikes) @@ -407,10 +407,6 @@ namespace MWGui else if (enchant->mData.mType == ESM::Enchantment::ConstantEffect) text += "\n#{sItemCastConstant}"; } - catch (const std::runtime_error& ex) - { - - } } // this the maximum width of the tooltip before it starts word-wrapping diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 032fc0a35..fa7542060 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -1144,27 +1144,17 @@ namespace MWRender if (enchantmentName.empty()) return result; - const ESM::Enchantment* enchantment = NULL; - try - { - enchantment = MWBase::Environment::get().getWorld()->getStore().get().find(enchantmentName); - } - catch (const std::runtime_error& ex) - { + const ESM::Enchantment* enchantment = MWBase::Environment::get().getWorld()->getStore().get().search(enchantmentName); + if (!enchantment) return result; - } + assert (enchantment->mEffects.mList.size()); - const ESM::MagicEffect* magicEffect = NULL; - try - { - magicEffect = MWBase::Environment::get().getWorld()->getStore().get().find( + const ESM::MagicEffect* magicEffect = MWBase::Environment::get().getWorld()->getStore().get().search( enchantment->mEffects.mList.front().mEffectID); - } - catch (const std::runtime_error& ex) - { + if (!magicEffect) return result; - } + result.x() = magicEffect->mData.mRed / 255.f; result.y() = magicEffect->mData.mGreen / 255.f; result.z() = magicEffect->mData.mBlue / 255.f;