Skip to content

StackOverflow in DefaultRasterizer.AddContainedLineF24Dot8 when invoking DrawLine #403

@CptWesley

Description

@CptWesley

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of ImageSharp.Drawing
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported

ImageSharp.Drawing version

3.0.0

Other ImageSharp packages and versions

ImageSharp 4.0.0

Environment (Operating system, version and so on)

Windows 11

.NET Framework version

.NET 10 & .NET 11 preview 4

Description

Since updates to the new major versions of ImageSharp and ImageSharp. Drawing I have been experiencing some very rare and impossible to consistently reproduce issues when drawing lines. One of these instances I ran into is a stackoverflow where the DefaultRasterizer.AddContainedLineF24Dot8 method was invoked over 12.000 times recursively. Since the occurrence is so rare and my attempts to reproduce it have failed, I find it a bit hard to describe what could be potentially causing this. It must be noted that this snippet of code has worked fine for over a year before updating to the new major versions. The change made at the time was to include the extra Paint operation, rather than drawing the line directly in the Mutate operation. My apologies for not being able to provide more information, but this is all the information I was able to gather.

Steps to Reproduce

var image = new Image<Rgba32>(width, height, new Rgba32(0, 0, 0, 0));

// ...

image.Mutate(ctx =>
{
    ctx.Paint(canvas =>
    {
        canvas.Clear(Brushes.Solid(SixLabors.ImageSharp.Color.Transparent));
        var path = GetPath(); // 5 points where 1st = 5th point. Is different each time.

        var pen = new SolidPen(SixLabors.ImageSharp.Color.Black, 4f);
        canvas.DrawLine(pen, path);
    });
});

Images

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions