From f6c1d3e635b2e7d26175c25153a06ac148876e2e Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 14 May 2014 14:00:31 -0700 Subject: [PATCH] clean up animations --- libraries/models/src/ModelItem.cpp | 19 ++++++++++++++++++- libraries/models/src/ModelItem.h | 2 ++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/libraries/models/src/ModelItem.cpp b/libraries/models/src/ModelItem.cpp index 7a4f9e3edc..c04f9a76ae 100644 --- a/libraries/models/src/ModelItem.cpp +++ b/libraries/models/src/ModelItem.cpp @@ -671,9 +671,26 @@ void ModelItem::adjustEditPacketForClockSkew(unsigned char* codeColorBuffer, ssi } -QMap ModelItem::_loadedAnimations; // TODO: cleanup?? +QMap ModelItem::_loadedAnimations; // TODO: improve cleanup by leveraging the AnimationPointer(s) AnimationCache ModelItem::_animationCache; +// This class/instance will cleanup the animations once unloaded. +class ModelAnimationsBookkeeper { +public: + ~ModelAnimationsBookkeeper() { + ModelItem::cleanupLoadedAnimations(); + } +}; + +ModelAnimationsBookkeeper modelAnimationsBookkeeperInstance; + +void ModelItem::cleanupLoadedAnimations() { + foreach(AnimationPointer animation, _loadedAnimations) { + animation.clear(); + } + _loadedAnimations.clear(); +} + Animation* ModelItem::getAnimation(const QString& url) { AnimationPointer animation; diff --git a/libraries/models/src/ModelItem.h b/libraries/models/src/ModelItem.h index 18074fbe13..847e58e7c2 100644 --- a/libraries/models/src/ModelItem.h +++ b/libraries/models/src/ModelItem.h @@ -278,6 +278,8 @@ public: bool getAnimationIsPlaying() const { return _animationIsPlaying; } float getAnimationFrameIndex() const { return _animationFrameIndex; } float getAnimationFPS() const { return _animationFPS; } + + static void cleanupLoadedAnimations(); protected: glm::vec3 _position;