containsPoint: for UIBezierPath crashes
Asked Answered
C

2

8

I'm parsing a SVG file to UIBezierPath. I'd like to know whether a CGPoint is inside or outside the UIBezierPath. To do this I use containsPoint:. When I run this in the simulator everthing works fine (almost!). When I run it a iPad device it crashes on some paths and points. I'm calling closePath on every UIBezierPath before I call containsPoint:.

Here are some paths and points, which makes it crash (I randomize the points, so there might be more crash points):

Crash Points: (659.0, 444.0), (659.0, 443.0)
SVG Path: M661 446 c1 -1 3 -1 4 -1 1 -1 2 -2 2 -4 0 -2 0 -2 -2 -2 0 1 -2 1 -3 1 -2 0 -3 1 -3 2 0 1 0 2 0 3 0 0 1 1 2 1z

Crash Points: (533.0, 458.0), (533.0, 457.0)
SVG Path: M535 460 c0 0 1 -1 1 -2 1 -2 0 -3 -1 -3 0 0 -1 0 -2 1 0 1 0 2 0 3 1 0 1 1 2 1z

I can't figure out why it crashes. To me it should return YES or NO no matter what path or point it gets.

Why does it crash? :-(

Compander answered 19/9, 2012 at 7:9 Comment(3)
please post the code where you call containsPoint:Biddick
i can reproduce your crashes on the device (maybe you should file a bugreport to apple). Very strange. If Performance/precision is not that crucial in your case, you could rasterize the path and do a simple color-lookup for testing.Hamartia
I experience the same behavior: Works on simulator, crashes on device. Looks like a genuine bug worthy of https://bugreport.apple.com/. By the way, you'll have to provide them more information than above, e.g. show them the actual path you generated rather than the SVG string.Saccharin
C
0

It turns out the crash is a bug in the framework. This answer provides another way to determine whether a point is inside a UIBezierPath.

Compander answered 22/10, 2012 at 6:53 Comment(0)
B
2

Try the hit testing techniques in this post:

http://oleb.net/blog/2012/02/cgpath-hit-testing/

I've use this in one of my apps and it works without any problems. His examples were all I needed to get things working. If you need more help I can post some of my code tonight.

If you need any help with the SVG parsing, I forked a github project to do parsing of SVG paths, and extended it to support line and polyline elements. I'm converting SVGs to UIBezierPaths and then doing animation and hit testing for finger drawing.

https://github.com/stevekohls/PocketSVG

Biotype answered 5/10, 2012 at 14:48 Comment(0)
C
0

It turns out the crash is a bug in the framework. This answer provides another way to determine whether a point is inside a UIBezierPath.

Compander answered 22/10, 2012 at 6:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.