I've been dealing with a pernicious crash bug in my iPhone app, which is consistently reproducible in the version downloaded from the App Store, but not at all in the debug version. I have produced a workaround, which works by excluding the critical drawing code from running during a UIViewController animation.

* The crash log indicates that there is an assert failure in CGPathAddLineToPoint.
* The app uses the drawing functions CGContextMoveToPoint, CGContextAddLineToPoint, and CGContextStrokePath. The functions CGPathCreateMutable, CGPathAddLines, and CGContextAddPath are also used, but the app still crashes even in configurations that (should) avoid invoking them.
* The crash happens consistently when lines are drawn on a view while its UIViewController is being presented (animated). Otherwise, the drawing works without issue.
* I have confirmed in the debug version that every point of every line drawn is real and within the boundaries of the view.
* The app crashes immediately on iOS7 when the drawing is attempted. On iOS5 and iOS6, the app stops responding for 30 seconds before crashing, leaving behind an "Unknown" crash log with no information.
* The only cases I could find on the web similar to this problem were CGFloatIsValid assert failures in CGPathAddLineToPoint in OS X apps (including iPhoto crash logs posted to Apple's support forums).

I can't say much more about it because the app never crashes or even gives a warning in the debug version. Has anyone else encountered this bug? Is there a better way to resolve this issue?

You can view the workaround in action in the release version [on the App Store](http://itunes.apple.com/app/id474209552). You can see that the line drawing on the graph is delayed until after the animation completes when you push the [Graph] button, when the calculator is in 2D mode.

The important part of the crash log (from an iPhone 5S running iOS 7.0.3, app armv7):

```
Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Triggered by Thread:  0

Thread 0 Crashed:
0   libsystem_kernel.dylib          0x3a5e11fc __pthread_kill + 8
1   libsystem_pthread.dylib         0x3a648a4f pthread_kill + 55
2   libsystem_c.dylib               0x3a592029 abort + 73
3   libsystem_c.dylib               0x3a571c67 __assert_rtn + 179
4   CoreGraphics                    0x2fd566f5 CGPathAddLineToPoint + 149
5   (My App)                        0x001464cd 0xd7000 + 455885
6   UIKit                           0x324d4dd5 -[UIView(CALayerDelegate) drawLayer:inContext:] + 369
7   QuartzCore                      0x3210aa75 -[CALayer drawInContext:] + 97
8   QuartzCore                      0x320f4241 CABackingStoreUpdate_ + 1857
9   QuartzCore                      0x321ce2e9 ___ZN2CA5Layer8display_Ev_block_invoke + 49
10  QuartzCore                      0x320f3af1 x_blame_allocations + 81
11  QuartzCore                      0x320f37a3 CA::Layer::display_() + 1115
12  QuartzCore                      0x320d7365 CA::Layer::display_if_needed(CA::Transaction*) + 205
13  QuartzCore                      0x320d6ffd CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 21
14  QuartzCore                      0x320d6a09 CA::Context::commit_transaction(CA::Transaction*) + 225
15  QuartzCore                      0x320d681b CA::Transaction::commit() + 311
16  QuartzCore                      0x320d0549 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 53
17  CoreFoundation                  0x2fc9bf67 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 19
18  CoreFoundation                  0x2fc998f3 __CFRunLoopDoObservers + 283
19  CoreFoundation                  0x2fc99c3f __CFRunLoopRun + 735
20  CoreFoundation                  0x2fc0446d CFRunLoopRunSpecific + 521
21  CoreFoundation                  0x2fc0424f CFRunLoopRunInMode + 103
22  GraphicsServices                0x349382e7 GSEventRunModal + 135
23  UIKit                           0x324b9841 UIApplicationMain + 1133
24  (My App)                        0x000de723 0xd7000 + 30499
25  (My App)                        0x000dde0c 0xd7000 + 28172

```