Skip to content

Commit

Permalink
Merge pull request #84942 from TokageItLab/leak-res-track-cache
Browse files Browse the repository at this point in the history
Fix ValueTrack with Resource is leaking
  • Loading branch information
akien-mga authored Nov 15, 2023
2 parents cc135c5 + f853d67 commit 56a2b14
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions scene/animation/animation_mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
19 changes: 19 additions & 0 deletions scene/animation/animation_mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ class AnimationMixer : public Node {
Object *object = nullptr;
ObjectID object_id;
real_t total_weight = 0.0;

virtual ~TrackCache() {}
};

struct TrackCacheTransform : public TrackCache {
Expand All @@ -164,6 +166,7 @@ class AnimationMixer : public Node {
TrackCacheTransform() {
type = Animation::TYPE_POSITION_3D;
}
~TrackCacheTransform() {}
};

struct RootMotionCache {
Expand All @@ -178,6 +181,7 @@ class AnimationMixer : public Node {
float value = 0;
int shape_index = -1;
TrackCacheBlendShape() { type = Animation::TYPE_BLEND_SHAPE; }
~TrackCacheBlendShape() {}
};

struct TrackCacheValue : public TrackCache {
Expand All @@ -187,10 +191,16 @@ class AnimationMixer : public Node {
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 {
Expand All @@ -200,6 +210,7 @@ class AnimationMixer : public Node {
TrackCacheBezier() {
type = Animation::TYPE_BEZIER;
}
~TrackCacheBezier() {}
};

// Audio stream information for each audio stream placed on the track.
Expand Down Expand Up @@ -228,6 +239,7 @@ class AnimationMixer : public Node {
TrackCacheAudio() {
type = Animation::TYPE_AUDIO;
}
~TrackCacheAudio() {}
};

struct TrackCacheAnimation : public TrackCache {
Expand All @@ -236,6 +248,7 @@ class AnimationMixer : public Node {
TrackCacheAnimation() {
type = Animation::TYPE_ANIMATION;
}
~TrackCacheAnimation() {}
};

RootMotionCache root_motion_cache;
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 56a2b14

Please sign in to comment.