From 1a6db097edd224b5a4a8b70b9de46e52f34f7d96 Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 29 Jul 2014 15:32:22 +0200 Subject: [PATCH] Fix dangling MWWorld::Ptrs in enchanting dialog after loading save game (Fixes #1722) --- apps/openmw/mwgui/enchantingdialog.cpp | 23 +++++++++++++++++------ apps/openmw/mwgui/enchantingdialog.hpp | 2 ++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwgui/enchantingdialog.cpp b/apps/openmw/mwgui/enchantingdialog.cpp index d7e79e7a2..e89777bee 100644 --- a/apps/openmw/mwgui/enchantingdialog.cpp +++ b/apps/openmw/mwgui/enchantingdialog.cpp @@ -58,9 +58,6 @@ namespace MWGui void EnchantingDialog::open() { center(); - - setSoulGem(MWWorld::Ptr()); - setItem(MWWorld::Ptr()); } void EnchantingDialog::setSoulGem(const MWWorld::Ptr &gem) @@ -78,7 +75,6 @@ namespace MWGui mSoulBox->setUserData(gem); mEnchanting.setSoulGem(gem); } - updateLabels(); } void EnchantingDialog::setItem(const MWWorld::Ptr &item) @@ -96,7 +92,6 @@ namespace MWGui mItemBox->setUserData(item); mEnchanting.setOldItem(item); } - updateLabels(); } void EnchantingDialog::exit() @@ -148,6 +143,9 @@ namespace MWGui mPtr = actor; + setSoulGem(MWWorld::Ptr()); + setItem(MWWorld::Ptr()); + startEditing (); mPrice->setVisible(true); mPriceText->setVisible(true); @@ -167,6 +165,7 @@ namespace MWGui startEditing(); setSoulGem(soulgem); + setItem(MWWorld::Ptr()); mPrice->setVisible(false); mPriceText->setVisible(false); @@ -177,6 +176,16 @@ namespace MWGui { MWBase::Environment::get().getWindowManager()->removeGuiMode (GM_Dialogue); MWBase::Environment::get().getWindowManager()->removeGuiMode (GM_Enchanting); + resetReference(); + } + + void EnchantingDialog::resetReference() + { + ReferenceInterface::resetReference(); + setItem(MWWorld::Ptr()); + setSoulGem(MWWorld::Ptr()); + mPtr = MWWorld::Ptr(); + mEnchanting.setEnchanter(MWWorld::Ptr()); } void EnchantingDialog::onCancelButtonClicked(MyGUI::Widget* sender) @@ -219,8 +228,8 @@ namespace MWGui void EnchantingDialog::onSoulSelected(MWWorld::Ptr item) { mItemSelectionDialog->setVisible(false); - mEnchanting.setSoulGem(item); + mEnchanting.setSoulGem(item); if(mEnchanting.getGemCharge()==0) { MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage32}"); @@ -228,6 +237,7 @@ namespace MWGui } setSoulGem(item); + updateLabels(); } void EnchantingDialog::onSoulCancel() @@ -252,6 +262,7 @@ namespace MWGui else { setSoulGem(MWWorld::Ptr()); + updateLabels(); } } diff --git a/apps/openmw/mwgui/enchantingdialog.hpp b/apps/openmw/mwgui/enchantingdialog.hpp index b75ae8280..5b67d199b 100644 --- a/apps/openmw/mwgui/enchantingdialog.hpp +++ b/apps/openmw/mwgui/enchantingdialog.hpp @@ -29,6 +29,8 @@ namespace MWGui void startEnchanting(MWWorld::Ptr actor); void startSelfEnchanting(MWWorld::Ptr soulgem); + virtual void resetReference(); + protected: virtual void onReferenceUnavailable(); virtual void notifyEffectsChanged ();