From 70fe539ee46519e5d2bacdeed382614791d7b57a Mon Sep 17 00:00:00 2001 From: elsid Date: Sun, 2 Oct 2022 13:50:41 +0200 Subject: [PATCH] Fix resetting player's animation on game loading When game is loaded player's animation is replaced by a new object. Old object is destructed without explicit removeFromScene call. --- apps/openmw/mwrender/actoranimation.cpp | 14 +++++++++++--- apps/openmw/mwrender/actoranimation.hpp | 1 + apps/openmw/mwrender/animation.cpp | 10 +++++++++- apps/openmw/mwrender/animation.hpp | 2 ++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwrender/actoranimation.cpp b/apps/openmw/mwrender/actoranimation.cpp index 3d5daf74e0..b77115f2dd 100644 --- a/apps/openmw/mwrender/actoranimation.cpp +++ b/apps/openmw/mwrender/actoranimation.cpp @@ -58,7 +58,10 @@ ActorAnimation::ActorAnimation(const MWWorld::Ptr& ptr, osg::ref_ptr removeEffects(); } -ActorAnimation::~ActorAnimation() = default; +ActorAnimation::~ActorAnimation() +{ + removeFromSceneImpl(); +} PartHolderPtr ActorAnimation::attachMesh(const std::string& model, const std::string& bonename, bool enchantedGlow, osg::Vec4f* glowColor) { @@ -573,9 +576,14 @@ void ActorAnimation::removeHiddenItemLight(const MWWorld::ConstPtr& item) 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 41978eb785..d1f89295a3 100644 --- a/apps/openmw/mwrender/actoranimation.hpp +++ b/apps/openmw/mwrender/actoranimation.hpp @@ -65,6 +65,7 @@ class ActorAnimation : public Animation, public MWWorld::ContainerStoreListener 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 9d910c00f9..a394e67cf5 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -543,7 +543,10 @@ namespace MWRender mLightListCallback = new SceneUtil::LightListCallback; } - Animation::~Animation() = default; + Animation::~Animation() + { + removeFromSceneImpl(); + } void Animation::setActive(int active) { @@ -1783,6 +1786,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 1b5f5aa298..f3731c5423 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -344,6 +344,8 @@ protected: */ virtual void addControllers(); + void removeFromSceneImpl(); + public: Animation(const MWWorld::Ptr &ptr, osg::ref_ptr parentNode, Resource::ResourceSystem* resourceSystem);