From 86f2cd5848d86f36dc31a99682dec3e6d93bd8ef Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 14 Aug 2013 20:26:50 -0700 Subject: [PATCH] Use dynamic_cast to get the LiveCellRef --- apps/openmw/mwworld/livecellref.hpp | 2 ++ apps/openmw/mwworld/ptr.hpp | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwworld/livecellref.hpp b/apps/openmw/mwworld/livecellref.hpp index 4c6c8f7f7..64462cb3f 100644 --- a/apps/openmw/mwworld/livecellref.hpp +++ b/apps/openmw/mwworld/livecellref.hpp @@ -28,6 +28,8 @@ namespace MWWorld LiveCellRefBase(std::string type, const ESM::CellRef &cref=ESM::CellRef()) : mTypeName(type), mRef(cref), mData(mRef) { } + /* Need this for the class to be recognized as polymorphic */ + virtual ~LiveCellRefBase() { } }; /// A reference to one object (of any type) in a cell. diff --git a/apps/openmw/mwworld/ptr.hpp b/apps/openmw/mwworld/ptr.hpp index 4ee223950..f5f2eedea 100644 --- a/apps/openmw/mwworld/ptr.hpp +++ b/apps/openmw/mwworld/ptr.hpp @@ -46,8 +46,8 @@ namespace MWWorld template MWWorld::LiveCellRef *get() const { - if(mRef && mRef->mTypeName == typeid(T).name()) - return static_cast*>(mRef); + MWWorld::LiveCellRef *ref = dynamic_cast*>(mRef); + if(ref) return ref; std::stringstream str; str<< "Bad LiveCellRef cast to "<