CodingMeSwiftly / UIBezierPath-Superpowers

MIT License
78 stars 16 forks source link

Release Crashing #7

Closed jerryhalstead closed 6 years ago

jerryhalstead commented 6 years ago

Been using the code no problems for days. Sent out a beta and it crashes for everyone. I don't know why, but it seems that when it gets to this point it crashes:
block?(element.pointee)

I could only get it to crash doing a release build and I'm not proficient enough at swift to understand why it's failing.

Searching around for ideas/code I ran across this devforum post (notably Eskimo's): https://forums.developer.apple.com/message/15725#15725

I used this code he posted:

typealias CGPathApplierBlock = @convention(block) (CGPathElement) -> Void

extension CGPath { func apply(body: CGPathApplierBlock) { self.apply(info: unsafeBitCast(body, to: UnsafeMutableRawPointer.self)) { (info, element) in let block2 = unsafeBitCast(info, to: CGPathApplierBlock.self) block2(element.pointee) } } }

And now instead of: enumeratePathElements { element in

I use: cgPath.apply { element in

And it works without crashing in debug and release build. I'm building with xcode 9.1 and most testing on iOS 11 devices.

CodingMeSwiftly commented 6 years ago

Thank you so much for finding this and providing the fix! Fix is implemented, tested and merged.