diff options
| author | Alistair Leslie-Hughes <leslie_alistair@hotmail.com> | 2023-11-16 18:47:46 +1100 |
|---|---|---|
| committer | Alistair Leslie-Hughes <leslie_alistair@hotmail.com> | 2023-12-12 07:33:35 +1100 |
| commit | ea84effb845f7959b2eed362855e5c0e8ab68f20 (patch) | |
| tree | 1e80ee0c50982f0fba063eae2aec545ff2ed0f91 | |
| parent | 0c03d25ba499214bd04a55e5df9ea17c9b3a344a (diff) | |
| download | redot-engine-ea84effb845f7959b2eed362855e5c0e8ab68f20.tar.gz | |
Replace memory allocation point of ValueTrack correctly in AnimationMixer
When a animation track doesn't have an keys, it's possible that we leak memory due the ERR_CONTINUE_MSG macro usage.
By checking the error condition first, we avoid a allocation and thus the leak.
| -rw-r--r-- | scene/animation/animation_mixer.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/scene/animation/animation_mixer.cpp b/scene/animation/animation_mixer.cpp index c6d69cf622..da00d1dd7b 100644 --- a/scene/animation/animation_mixer.cpp +++ b/scene/animation/animation_mixer.cpp @@ -638,6 +638,10 @@ bool AnimationMixer::_update_caches() { switch (track_type) { case Animation::TYPE_VALUE: { + // If a value track without a key is cached first, the initial value cannot be determined. + // It is a corner case, but which may cause problems with blending. + ERR_CONTINUE_MSG(anim->track_get_key_count(i) == 0, "AnimationMixer: '" + String(E) + "', Value Track: '" + String(path) + "' must have at least one key to cache for blending."); + TrackCacheValue *track_value = memnew(TrackCacheValue); if (resource.is_valid()) { @@ -654,9 +658,6 @@ bool AnimationMixer::_update_caches() { track = track_value; - // If a value track without a key is cached first, the initial value cannot be determined. - // It is a corner case, but which may cause problems with blending. - ERR_CONTINUE_MSG(anim->track_get_key_count(i) == 0, "AnimationMixer: '" + String(E) + "', Value Track: '" + String(path) + "' must have at least one key to cache for blending."); track_value->init_value = anim->track_get_key_value(i, 0); track_value->init_value.zero(); |
