diff options
author | Rémi Verschelde <remi@verschelde.fr> | 2023-11-15 18:47:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-15 18:47:10 +0100 |
commit | 56a2b143a2d8868fdbaba798b7b0145516397f48 (patch) | |
tree | 2dd3b881d592a64adbe4798cecfb457100424e4c | |
parent | cc135c58218cfd48a2bc2a1fe4805578a3ae661c (diff) | |
parent | f853d675e8e2f3c517c1a1d6a0db4648f9d8d3b8 (diff) | |
download | redot-engine-56a2b143a2d8868fdbaba798b7b0145516397f48.tar.gz |
Merge pull request #84942 from TokageItLab/leak-res-track-cache
Fix ValueTrack with Resource is leaking
-rw-r--r-- | scene/animation/animation_mixer.cpp | 4 | ||||
-rw-r--r-- | scene/animation/animation_mixer.h | 19 |
2 files changed, 21 insertions, 2 deletions
diff --git a/scene/animation/animation_mixer.cpp b/scene/animation/animation_mixer.cpp index fb17dae832..085dcd7556 100644 --- a/scene/animation/animation_mixer.cpp +++ b/scene/animation/animation_mixer.cpp @@ -445,7 +445,7 @@ bool AnimationMixer::is_active() const { void AnimationMixer::set_root_node(const NodePath &p_path) { root_node = p_path; - clear_caches(); + _clear_caches(); } NodePath AnimationMixer::get_root_node() const { @@ -454,7 +454,7 @@ NodePath AnimationMixer::get_root_node() const { void AnimationMixer::set_deterministic(bool p_deterministic) { deterministic = p_deterministic; - clear_caches(); + _clear_caches(); } bool AnimationMixer::is_deterministic() const { diff --git a/scene/animation/animation_mixer.h b/scene/animation/animation_mixer.h index 6aa050d1fb..9f7fbf6e50 100644 --- a/scene/animation/animation_mixer.h +++ b/scene/animation/animation_mixer.h @@ -143,6 +143,8 @@ protected: Object *object = nullptr; ObjectID object_id; real_t total_weight = 0.0; + + virtual ~TrackCache() {} }; struct TrackCacheTransform : public TrackCache { @@ -164,6 +166,7 @@ protected: TrackCacheTransform() { type = Animation::TYPE_POSITION_3D; } + ~TrackCacheTransform() {} }; struct RootMotionCache { @@ -178,6 +181,7 @@ protected: float value = 0; int shape_index = -1; TrackCacheBlendShape() { type = Animation::TYPE_BLEND_SHAPE; } + ~TrackCacheBlendShape() {} }; struct TrackCacheValue : public TrackCache { @@ -187,10 +191,16 @@ protected: bool is_continuous = false; bool is_using_angle = false; TrackCacheValue() { type = Animation::TYPE_VALUE; } + ~TrackCacheValue() { + // Clear ref to avoid leaking. + init_value = Variant(); + value = Variant(); + } }; struct TrackCacheMethod : public TrackCache { TrackCacheMethod() { type = Animation::TYPE_METHOD; } + ~TrackCacheMethod() {} }; struct TrackCacheBezier : public TrackCache { @@ -200,6 +210,7 @@ protected: TrackCacheBezier() { type = Animation::TYPE_BEZIER; } + ~TrackCacheBezier() {} }; // Audio stream information for each audio stream placed on the track. @@ -228,6 +239,7 @@ protected: TrackCacheAudio() { type = Animation::TYPE_AUDIO; } + ~TrackCacheAudio() {} }; struct TrackCacheAnimation : public TrackCache { @@ -236,6 +248,7 @@ protected: TrackCacheAnimation() { type = Animation::TYPE_ANIMATION; } + ~TrackCacheAnimation() {} }; RootMotionCache root_motion_cache; @@ -377,6 +390,12 @@ class AnimatedValuesBackup : public RefCounted { public: void set_data(const HashMap<NodePath, AnimationMixer::TrackCache *> p_data) { data = p_data; }; HashMap<NodePath, AnimationMixer::TrackCache *> get_data() const { return data; }; + + ~AnimatedValuesBackup() { + for (KeyValue<NodePath, AnimationMixer::TrackCache *> &K : data) { + memdelete(K.value); + } + } }; #endif |