mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
svg_loader: fix a infinite loop error by circular dependency.
Composition can be applied recursively if its children nodes have composition target to this one. This can be occured by wrong svg description, and tvg prevents this exception case. @Issue: https://github.com/Samsung/thorvg/issues/494
This commit is contained in:
parent
bb68a2d514
commit
19a3190245
2 changed files with 14 additions and 0 deletions
|
@ -190,6 +190,7 @@ struct SvgComposite
|
|||
CompositeMethod method; //TODO: Currently support either one method
|
||||
string *url;
|
||||
SvgNode* node;
|
||||
bool applying; //flag for checking circualr dependency.
|
||||
};
|
||||
|
||||
struct SvgColor
|
||||
|
|
|
@ -179,9 +179,20 @@ static void _applyComposition(Paint* paint, const SvgNode* node, float vx, float
|
|||
{
|
||||
if (node->style->comp.method == CompositeMethod::None) return;
|
||||
|
||||
/* Do not drop in Circular Dependency.
|
||||
Composition can be applied recursively if its children nodes have composition target to this one. */
|
||||
if (node->style->comp.applying) {
|
||||
#ifdef THORVG_LOG_ENABLED
|
||||
printf("SVG: Multiple Composition Tried! Check out Circular dependency?\n");
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
auto compNode = node->style->comp.node;
|
||||
if (!compNode || compNode->child.count == 0) return;
|
||||
|
||||
node->style->comp.applying = true;
|
||||
|
||||
auto comp = Shape::gen();
|
||||
comp->fill(255, 255, 255, 255);
|
||||
if (node->transform) comp->transform(*node->transform);
|
||||
|
@ -194,6 +205,8 @@ static void _applyComposition(Paint* paint, const SvgNode* node, float vx, float
|
|||
}
|
||||
|
||||
if (valid) paint->composite(move(comp), node->style->comp.method);
|
||||
|
||||
node->style->comp.applying = false;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue