diff --git a/src/Svg.Model/Drawables/DrawableBase.cs b/src/Svg.Model/Drawables/DrawableBase.cs index d7dca42016..d7d594757b 100644 --- a/src/Svg.Model/Drawables/DrawableBase.cs +++ b/src/Svg.Model/Drawables/DrawableBase.cs @@ -418,6 +418,11 @@ public virtual void DebugDrawBounds(SKCanvas canvas) | DrawAttributes.Opacity | DrawAttributes.Filter; + // When a filter references 'SourceGraphic', we must draw the element + // without applying its filter again to avoid infinite recursion. + private const DrawAttributes FilterSourceInput = + DrawAttributes.Filter; + protected virtual void PostProcessChildren(SKRect? clip, SKMatrix totalMatrix) { } @@ -425,7 +430,9 @@ protected virtual void PostProcessChildren(SKRect? clip, SKMatrix totalMatrix) SKPicture? IFilterSource.SourceGraphic(SKRect? clip) { PostProcessChildren(clip, SKMatrix.Identity); - return RecordGraphic(this, clip, DrawAttributes.None); + // Ignore the element's filter when rendering the source graphic so + // that filter primitives do not recursively re-enter filtering. + return RecordGraphic(this, clip, FilterSourceInput); } SKPicture? IFilterSource.BackgroundImage(SKRect? clip) => RecordBackground(this, clip, FilterBackgroundInput);