From f8c5f3a69cb52d9d0d7d6fada20df45dc03c0d2c Mon Sep 17 00:00:00 2001 From: Mira Grudzinska Date: Thu, 10 Apr 2025 05:13:52 +0200 Subject: [PATCH] lottie: follow path stabilization++ * lottie: fixes in follow path Each time the 'updateText' was called, the mask path (if the follow path existed) was appended to the previous one, causing it to grow infinitely. A 'clear' call on the existing path was missing. The positions on the follow path for distances larger than 2 x mask path length were not correctly calculated. * lottie: fix crash on follow path It could happen that the searched text position (distance from the start pointt) on the follow path was exactly equal to the path length. In such a case, the cmds pointer pointed to the last element, and in the next iteration, this caused a crash. --- src/loaders/lottie/tvgLottieModel.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/loaders/lottie/tvgLottieModel.cpp b/src/loaders/lottie/tvgLottieModel.cpp index b1a817a5..5fb1b89b 100644 --- a/src/loaders/lottie/tvgLottieModel.cpp +++ b/src/loaders/lottie/tvgLottieModel.cpp @@ -65,6 +65,7 @@ float LottieTextFollowPath::prepare(LottieMask* mask, float frameNo, float scale { this->mask = mask; Matrix m{1.0f / scale, 0.0f, 0.0f, 0.0f, 1.0f / scale, 0.0f, 0.0f, 0.0f, 1.0f}; + path.clear(); mask->pathset(frameNo, path, &m, tween, exps); pts = path.pts.data; @@ -109,10 +110,10 @@ Point LottieTextFollowPath::position(float lenSearched, float& angle) }; //beyond the curve - if (lenSearched > totalLen) { + if (lenSearched >= totalLen) { //shape is closed -> wrapping if (path.cmds.last() == PathCommand::Close) { - lenSearched -= totalLen; + while (lenSearched > totalLen) lenSearched -= totalLen; pts = path.pts.data; cmds = path.cmds.data; cmdsCnt = path.cmds.count; @@ -147,7 +148,7 @@ Point LottieTextFollowPath::position(float lenSearched, float& angle) while (cmdsCnt > 0) { auto dLen = length(); - if (currentLen + dLen <= lenSearched) { + if (currentLen + dLen < lenSearched) { shift(); currentLen += dLen; continue;