You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rendering an SvgDocument containing a gradient to a bitmap runs out of memory if the document is repeatedly rendered.
Example data
Example project that repeatedly renders an SvgDocument to a Bitmap and displays the bitmap in a PictureBox. SvgGradientTest.zip
Used Versions
Svg 3.4.2 (problem does not occur in earlier versions)
Windows 11
.NET 6
Additional information
This problem may be related to issue #978, which also uses a gradient.
The problem appears to be caused by SvgGradientServer.LoadStops(), which was introduced in version 3.4.2:
private void LoadStops(SvgVisualElement parent)
{
var gradient = this;
while (gradient?.Stops.Count == 0)
gradient = SvgDeferredPaintServer.TryGet<SvgGradientServer>(gradient.InheritGradient, parent);
if (gradient != null)
Stops.AddRange(gradient.Stops);
}
If this.Stops.Count is nonzero on entry, Stops.AddRange(gradient.Stops) will append this.Stops to itself. If this is done repeatedly, the length of this.Stops increases geometrically, leading to an out-of-memory condition. One solution is to check for this condition:
private void LoadStops(SvgVisualElement parent)
{
var gradient = this;
while (gradient?.Stops.Count == 0)
gradient = SvgDeferredPaintServer.TryGet<SvgGradientServer>(gradient.InheritGradient, parent);
if (gradient != null && gradient != this)
Stops.AddRange(gradient.Stops);
}
The text was updated successfully, but these errors were encountered:
Description
Rendering an SvgDocument containing a gradient to a bitmap runs out of memory if the document is repeatedly rendered.
Example data
Example project that repeatedly renders an SvgDocument to a Bitmap and displays the bitmap in a PictureBox.
SvgGradientTest.zip
Used Versions
Svg 3.4.2 (problem does not occur in earlier versions)
Windows 11
.NET 6
Additional information
This problem may be related to issue #978, which also uses a gradient.
The problem appears to be caused by SvgGradientServer.LoadStops(), which was introduced in version 3.4.2:
If this.Stops.Count is nonzero on entry, Stops.AddRange(gradient.Stops) will append this.Stops to itself. If this is done repeatedly, the length of this.Stops increases geometrically, leading to an out-of-memory condition. One solution is to check for this condition:
The text was updated successfully, but these errors were encountered: