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.
This commit is contained in:
Mira Grudzinska 2025-04-10 05:13:52 +02:00 committed by GitHub
parent eb67549295
commit f8c5f3a69c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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;