lottie: fix matte layer finding

Layer identifiers do not have to be unique within
the entire file - they are unique within a given
group. Searching the entire composition to find
the referenced matte was an incorrect approach.

Error introduced by 1ee79a6c2a

@Issue: https://github.com/thorvg/thorvg/issues/2349
This commit is contained in:
Mira Grudzinska 2024-06-04 00:20:52 +02:00 committed by Sergii Liebodkin
parent 7c687816c2
commit ca92d4a53b
2 changed files with 12 additions and 7 deletions

View file

@ -98,7 +98,7 @@ struct RenderContext
static void _updateChildren(LottieGroup* parent, float frameNo, Inlist<RenderContext>& contexts, LottieExpressions* exps);
static void _updateLayer(LottieLayer* root, LottieLayer* layer, float frameNo, LottieExpressions* exps);
static bool _buildComposition(LottieComposition* comp, LottieGroup* parent);
static bool _buildComposition(LottieComposition* comp, LottieLayer* parent);
static Shape* _draw(LottieGroup* parent, RenderContext* ctx);
static void _rotateX(Matrix* m, float degree)
@ -1315,7 +1315,7 @@ static void _attachFont(LottieComposition* comp, LottieLayer* parent)
}
static bool _buildComposition(LottieComposition* comp, LottieGroup* parent)
static bool _buildComposition(LottieComposition* comp, LottieLayer* parent)
{
if (parent->children.count == 0) return false;
if (parent->buildDone) return true;
@ -1334,11 +1334,7 @@ static bool _buildComposition(LottieComposition* comp, LottieGroup* parent)
child->matteTarget = static_cast<LottieLayer*>(*(c - 1));
}
//matte layer is specified by an index.
} else {
if (auto matte = comp->layerByIdx(child->mid)) {
child->matteTarget = matte;
}
}
} else child->matteTarget = parent->layerByIdx(child->mid);
}
if (child->matteTarget) {

View file

@ -571,6 +571,15 @@ struct LottieLayer : LottieGroup
Type type = Null;
bool autoOrient = false;
bool matteSrc = false;
LottieLayer* layerByIdx(int16_t idx)
{
for (auto child = children.begin(); child < children.end(); ++child) {
auto layer = static_cast<LottieLayer*>(*child);
if (layer->idx == idx) return layer;
}
return nullptr;
}
};