Skip to content
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

Range error in TClipperOffset.BuildNormals (Delphi) #867

Closed
rinntech-ak opened this issue Jul 5, 2024 · 1 comment
Closed

Range error in TClipperOffset.BuildNormals (Delphi) #867

rinntech-ak opened this issue Jul 5, 2024 · 1 comment

Comments

@rinntech-ak
Copy link

During using shrinking of paths I got range error in procedure BuildNormals.
If pathlength is zero (len=0) fNorms[len-1] accesses element -1

procedure TClipperOffset.BuildNormals;
var
i, len: integer;
begin
len := Length(fInPath);
SetLength(fNorms, len);
for i := 0 to len-2 do
fNorms[i] := GetUnitNormal(fInPath[i], fInPath[i+1]);
fNorms[len -1] := GetUnitNormal(fInPath[len -1], fInPath[0]);
end;

My suggest for fix (works fine in my project):
if len>0 then fNorms[len -1] := GetUnitNormal(fInPath[len -1], fInPath[0]);

Best regards
Andreas

@rakkie
Copy link

rakkie commented Jul 12, 2024

I am seeing the same exception when offsetting in C#.

Here is some minimal code that reproduces the issue.

using Clipper2Lib;

var path = new Path64 { new Point64(100,  100) };
var paths = new Paths64() { path };

var clipperOffset = new ClipperOffset();
clipperOffset.AddPaths(paths, JoinType.Miter, EndType.Polygon);

var solution = new Paths64();
clipperOffset.Execute(-10, solution);

Expected Result: Empty solution (as in previous Clipper versions)
Actual Result: Out of range exception.

regards,
Richard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants