From 633b0d52fc00874e168570575ef2cd0fc1e9673c Mon Sep 17 00:00:00 2001 From: Subhransu Mohanty Date: Tue, 11 Aug 2020 13:40:49 +0900 Subject: [PATCH] parser: Fix the keyframe cache logic. For some keyframes the cache function was not getting called. so move the cache logic to outer function and call it when the property is fully parsed. --- src/lottie/lottiemodel.h | 7 +++++-- src/lottie/lottieparser.cpp | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/lottie/lottiemodel.h b/src/lottie/lottiemodel.h index 6365887..234d921 100644 --- a/src/lottie/lottiemodel.h +++ b/src/lottie/lottiemodel.h @@ -165,8 +165,8 @@ struct Value { VPointF mEndValue; VPointF mInTangent; VPointF mOutTangent; - float mBezierLength; - bool mPathKeyFrame = false; + float mBezierLength{0}; + bool mPathKeyFrame{false}; void cache() { if (mPathKeyFrame) { @@ -267,6 +267,8 @@ public: (last < prevFrame && last < curFrame)); } + void cache() { for (auto &e : mKeyFrames) e.mValue.cache(); } + public: std::vector> mKeyFrames; }; @@ -358,6 +360,7 @@ public: return isStatic() ? false : animation().changed(prevFrame, curFrame); } + void cache() { if (!isStatic()) animation().cache();} private: template void construct(Tp &member, Tp &&val) diff --git a/src/lottie/lottieparser.cpp b/src/lottie/lottieparser.cpp index 1d54e18..c53d060 100644 --- a/src/lottie/lottieparser.cpp +++ b/src/lottie/lottieparser.cpp @@ -2078,8 +2078,7 @@ void LottieParserImpl::parseKeyFrame(model::DynamicProperty &obj) inTangent, outTangent, std::move(parsed.interpolatorKey)); list.push_back(std::move(keyframe)); } else { - // Last frame. cache some computaion - for (auto &e : list) e.mValue.cache(); + // Last frame ignore } } @@ -2116,6 +2115,7 @@ void LottieParserImpl::parseShapeProperty(model::Property &obj) Skip(nullptr); } } + obj.cache(); } template @@ -2155,6 +2155,7 @@ void LottieParserImpl::parsePropertyHelper(model::Property &obj) break; } } + obj.cache(); } } -- 2.34.1