From f853d675e8e2f3c517c1a1d6a0db4648f9d8d3b8 Mon Sep 17 00:00:00 2001 From: "Silc Lizard (Tokage) Renew" <61938263+TokageItLab@users.noreply.github.com> Date: Thu, 16 Nov 2023 01:51:22 +0900 Subject: [PATCH] Fix ValueTrack with Resource is leaking --- scene/animation/animation_mixer.cpp | 4 ++-- 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 fb17dae8323..085dcd75562 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 6aa050d1fb7..9f7fbf6e50d 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 p_data) { data = p_data; }; HashMap get_data() const { return data; }; + + ~AnimatedValuesBackup() { + for (KeyValue &K : data) { + memdelete(K.value); + } + } }; #endif