-
-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IndexOutOfRangeException when drawing line near top when Stroke > 1.5f #108
Comments
We are likely dealing with some fallout from #96. (Not unexpected considering the volume of the change.) Need to look into this. |
I just realized the |
@antonfirsov I can get all the tests to pass including the new ones listed here by adding private void SkipEdgesBeforeMinY()
{
if (this.edges.Length == 0)
{
return;
}
this.SubPixelY = this.edges[this.sorted0[0]].Y0;
int i0 = 1;
int i1 = 0;
// Do fake scans for the lines belonging to edge start and endpoints before minY
while (this.SubPixelY < this.minY && i0 < this.edges.Length)
{
this.EnterEdges();
this.LeaveEdges();
this.activeEdges.RemoveLeavingEdges();
float y0 = this.edges[this.sorted0[i0]].Y0;
float y1 = this.edges[this.sorted1[i1]].Y1;
if (y0 < y1)
{
this.SubPixelY = y0;
i0++;
}
else
{
this.SubPixelY = y1;
i1++;
}
}
} |
Just to mention. Also happens to me. I have AntiAlias= true |
Just for your information, the issue can be reproduced even if the thickness of the line is 1. I got an static void Main()
{
Image<Rgba32> image = new Image<Rgba32>(width: 500, height: 400);
var startPoint = new PointF(493.55447f, -87.83895f);
var endPoint = new PointF(500.0656f, 174.81201f);
image.Mutate(x => x.DrawLines(Color.Black, thickness: 1, startPoint, endPoint));
} The minimal Visual Studio solution to reproduce the issue: DrawLinesIssue.zip |
This method was developed in rush, after realizing that I need to handle the cases where lines are outside the drawing bounds ... looks like testing was insufficient. I need more time to debug into that crazy code and understand exactly why is the overflow happening. We should not block on this, so @JimBobSquarePants feel free to raise a PR with your fix, since it seems to make things better. Just let's include tests from both the OP and #108 (comment), and also have a look at the outputs. |
@antonfirsov Looks like my fix is bad. It's offsetting the values not actually processing the virtual edges. What I'm seeing during debugging given a stroke width of 3. while (this.SubPixelY < this.minY)
{
this.EnterEdges();
this.LeaveEdges();
this.activeEdges.RemoveLeavingEdges();
float y0 = this.edges[this.sorted0[i0]].Y0; // Always -1
float y1 = this.edges[this.sorted1[i1]].Y1; // Always 2
// Always true
if (y0 < y1)
{
this.SubPixelY = y0;
i0++;
}
else
{
this.SubPixelY = y1;
i1++;
}
} |
Looks like I have a fix. Will do some final testing |
build: Go back to drawing beta 10 to avoid SixLabors/ImageSharp.Drawing#108
Prerequisites
DEBUG
andRELEASE
modeDescription
Drawing a horizontal line across the top edge of an image results in an exception if the stroke width is greater than
1.5f
and antialiasing is disabled.Steps to Reproduce
The following test code was run and adapted from
ImageSharp.Drawing/tests/ImageSharp.Drawing.Tests/Issues/Issue_28.cs
Lines 18 to 35 in 48a803e
Then:
C:\Work\Github\ImageSharp.Drawing\tests\ImageSharp.Drawing.Tests> dotnet test -c Release --filter "Issue_28"
The existing tests pass, the altered stroke width tests fail:
System Configuration
Seems to be related to the new PolygonScanner SkipEdgesBeforeMinY code.
The text was updated successfully, but these errors were encountered: