diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-05-29 18:59:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-29 18:59:19 +0200 |
commit | c11bf884e0a127fb714a575f40fdc0b73fe54f2d (patch) | |
tree | f7161979f36b0c521d38a5a26f0203f683cd33bb /scene | |
parent | bc816f93c6ee15dd7a4e1a280dc0ec80c038dddf (diff) | |
parent | e03f9ead2148839a39039bef4eefdb1e2770f24f (diff) |
Merge pull request #25012 from avencherus/prevent-duplicate-keyframes
Do precision comparison to prevent the creation of keyframes with a time that already exists
Diffstat (limited to 'scene')
-rw-r--r-- | scene/resources/animation.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index ebfcd51247..6ab78326b2 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -819,15 +819,17 @@ int Animation::_insert(float p_time, T &p_keys, const V &p_value) { while (true) { - if (idx == 0 || p_keys[idx - 1].time < p_time) { - //condition for insertion. - p_keys.insert(idx, p_value); - return idx; - } else if (p_keys[idx - 1].time == p_time) { + // Condition for replacement. + if (idx > 0 && Math::is_equal_approx(p_keys[idx - 1].time, p_time)) { - // condition for replacing. p_keys.write[idx - 1] = p_value; return idx - 1; + + // Condition for insert. + } else if (idx == 0 || p_keys[idx - 1].time < p_time) { + + p_keys.insert(idx, p_value); + return idx; } idx--; |