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

A bug in Path Extrusion #128

Open
Crash22191 opened this issue Aug 23, 2024 · 2 comments
Open

A bug in Path Extrusion #128

Crash22191 opened this issue Aug 23, 2024 · 2 comments

Comments

@Crash22191
Copy link

Crash22191 commented Aug 23, 2024

I'm not very high level in math and not sure what the proper fix should be, but in Path+Shapes.swift extrusionContours there is a check for point count being bigger than 1, while later on in tries to access points[2] which fails if the count is 2 and it was causing crashes on my end. I changed the count check to 2 which fixed it, but again not sure if it's a correct solution here.

...
        let count = points.count
        guard count > 1 else {
            return [translated(by: p0.position)]
        }
...
        if along.isClosed  {
            for i in 1 ..< count {
                addShape(points[(i < count - 1) ? i + 1 : 1])
            }
            addShape(points[2])
            shape = shapes.last!
            shapes[shapes.count - 1] = shapes[0]
        } else {
            addShape(p0, nil)
            for point in points.dropFirst(2) {
                addShape(point)
            }
            let last2 = points.suffix(2).map { $0.position }
            twistShape(last2[1] - last2[0])
            addShape(points.last!, nil)
            shape = shapes.last!
        }
        
@nicklockwood
Copy link
Owner

@Crash22191 thanks! Do you happen to have a copy of the input path that produced the crash? It would help me to write a test case

@Crash22191
Copy link
Author

Unfortunately I don't, these points are generated on runtime and different every time on my end.

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

2 participants