diff options
-rw-r--r-- | src/animation/backend/animationclip.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/animation/backend/animationclip.cpp b/src/animation/backend/animationclip.cpp index a95e14d74..f051d68d9 100644 --- a/src/animation/backend/animationclip.cpp +++ b/src/animation/backend/animationclip.cpp @@ -354,15 +354,18 @@ void AnimationClip::clearData() float AnimationClip::findDuration() { // Iterate over the contained fcurves and find the longest one - double tMax = 0.0; + float tMax = 0.f; + float tMin = 1.0f; for (const Channel &channel : qAsConst(m_channels)) { for (const ChannelComponent &channelComponent : qAsConst(channel.channelComponents)) { - const float t = channelComponent.fcurve.endTime(); - if (t > tMax) - tMax = t; + const float tStart = channelComponent.fcurve.startTime(); + const float tEnd = channelComponent.fcurve.endTime(); + tMax = std::max(tEnd, tMax); + tMin = std::min(tStart, tMin); } } - return tMax; + // We can't have a negative duration + return std::max(tMax - tMin, 0.0f); } int AnimationClip::findChannelComponentCount() |