diff --git a/apps/openmw/mwrender/actoranimation.cpp b/apps/openmw/mwrender/actoranimation.cpp index ed87d64516..676dfb5082 100644 --- a/apps/openmw/mwrender/actoranimation.cpp +++ b/apps/openmw/mwrender/actoranimation.cpp @@ -60,7 +60,10 @@ namespace MWRender removeEffects(); } - ActorAnimation::~ActorAnimation() = default; + ActorAnimation::~ActorAnimation() + { + removeFromSceneImpl(); + } PartHolderPtr ActorAnimation::attachMesh( const std::string& model, std::string_view bonename, bool enchantedGlow, osg::Vec4f* glowColor) @@ -584,9 +587,13 @@ namespace MWRender void ActorAnimation::removeFromScene() { - for (const auto& [k, v] : mItemLights) - mInsert->removeChild(v); + removeFromSceneImpl(); Animation::removeFromScene(); } + void ActorAnimation::removeFromSceneImpl() + { + for (const auto& [k, v] : mItemLights) + mInsert->removeChild(v); + } } diff --git a/apps/openmw/mwrender/actoranimation.hpp b/apps/openmw/mwrender/actoranimation.hpp index 71b9ad89cb..d82dc41540 100644 --- a/apps/openmw/mwrender/actoranimation.hpp +++ b/apps/openmw/mwrender/actoranimation.hpp @@ -68,6 +68,7 @@ namespace MWRender void addHiddenItemLight(const MWWorld::ConstPtr& item, const ESM::Light* esmLight); void removeHiddenItemLight(const MWWorld::ConstPtr& item); void resetControllers(osg::Node* node); + void removeFromSceneImpl(); typedef std::map> ItemLightMap; ItemLightMap mItemLights; diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index f11d004f11..088ecd4600 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -533,7 +533,10 @@ namespace MWRender mLightListCallback = new SceneUtil::LightListCallback; } - Animation::~Animation() = default; + Animation::~Animation() + { + removeFromSceneImpl(); + } void Animation::setActive(int active) { @@ -1791,6 +1794,11 @@ namespace MWRender } void Animation::removeFromScene() + { + removeFromSceneImpl(); + } + + void Animation::removeFromSceneImpl() { if (mGlowLight != nullptr) mInsert->removeChild(mGlowLight); diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index b9a8501bdc..756f7534b7 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -344,6 +344,8 @@ namespace MWRender */ virtual void addControllers(); + void removeFromSceneImpl(); + public: Animation( const MWWorld::Ptr& ptr, osg::ref_ptr parentNode, Resource::ResourceSystem* resourceSystem);