From e03f9ead2148839a39039bef4eefdb1e2770f24f Mon Sep 17 00:00:00 2001 From: Jared Date: Tue, 15 Jan 2019 17:36:22 +0200 Subject: [PATCH] Do precision comparison to prevent the creation of keyframes with a time that already exists. --- scene/resources/animation.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index 9c79b2ba3b5..8ee824dbe27 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--;