title: Crashing when trying to present UIImagePickerController modally on iPhone
body: <p>My app is crashing when I try to present a <code>UIImagePickerController</code> from a particular view controller. </p>
  
  <p>I have an object, <code>CLYImagePickerController</code>, that handles simple things for the <code>UIImagePickerController</code>, such as creating, presenting, and handling a <code>UIAlertView</code> that presents options for the user on which kind of <code>UIImagePickerController</code> to present, and handling image selection by the user. This object tells a delegate view controller to present a <code>UIImagePickerController</code> with the following method:</p>
  
  <pre><code>- (void)showImagePickerForSourceType:(UIImagePickerControllerSourceType)sourceType
  {
      UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
      imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
      imagePickerController.sourceType = sourceType;
      imagePickerController.delegate = self;
  
      [self.delegate presentViewController:imagePickerController animated:YES completion:nil];
  }
  </code></pre>
  
  <hr>
  
  <p><strong>EDIT 11/27/2013:</strong>
  <code>self</code> is the <code>CLYImagePickerController</code> described in the second paragraph. It is just an NSObject subclass. <code>CLYImagePickerController</code>'s <code>delegate</code> is defined in the following way:</p>
  
  <pre><code>@property (weak, nonatomic) UIViewController &lt;CLYImagePickerControllerDelegate&gt; *delegate;
  </code></pre>
  
  <p>The <code>CLYImagePickerController</code>'s purpose is to allow a view controller (the <code>delegate</code>) to call upon it to show an action sheet in the view controller's view, which when acted upon can call up a <code>UIImagePickerController</code> whose source type is determined by the action sheet button that was tapped. Basically, <code>CLYImagePickerController</code> handles a bunch of repeated code that would otherwise clutter the <code>delegate</code> view controller's code, and allows for a uniform presentation style throughout the app where image pickers are used.</p>
  
  <hr>
  
  <p>For a particular view controller, which happens to be large because it handles many aspects of a <code>UITableView</code> as well as a <code>UITextView</code>, presenting the <code>UIImagePickerController</code> of source type <code>UIImagePickerControllerSourceTypePhotoLibrary</code> causes the app to crash with a <code>EXC_BAD_ACCESS</code> exception almost every time (there are some rare instances where the app does not crash when the picker is launched, but rebuilding without making any changes to the project will usually reverse this and the app will begin crashing again). Again, I think it is important to stress that these crashes occur <strong>only when a <code>UIImagePickerController</code> with source type <code>UIImagePickerControllerSourceTypePhotoLibrary</code> is presented.</strong> Presenting a <code>UIImagePickerController</code> with source type <code>UIImagePickerControllerSourceTypeCamera</code> launches just fine.</p>
  
  <p>I have supplied a crash log from one of these crashes at the bottom of the post. </p>
  
  <p>To make sure that the issue was not with my <code>CLYImagePickerController</code> object, I tested it using an empty view controller whose only function is to act as a delegate for a <code>CLYImagePickerController</code>. In this view, the <code>UIImagePickerController</code> launches properly every time without fail for both source types. This has led me to believe that there is something in the problematic view controller's code that is interfering somehow with the <code>UIImagePickerController</code>, but I don't know what it could be. Has anyone else had an issue similar to this who could shed some light on the subject?</p>
  
  <p>What's strange is that after launching a picker with a photo library source type in the testing view, the problem view controller is then able to present a picker with a photo library source type without any issues. Is something being set globally when I present a <code>UIImagePickerController</code> with source type <code>UIImagePickerControllerSourceTypePhotoLibrary</code> for the first time that allows me to present it again without issues in the problematic view controller?</p>
  
  <h2>Crash Log</h2>
  
  <p>The following is an example stack trace of one of these crashes. I don't really know what all this means. It seems like there's some sort of issue accessing something related to a font somewhere? I don't know.</p>
  
  <pre><code>Thread 0: Crashed: com.apple.main-thread
  0  CoreText                       0x2db76d52 TComponentFont::GetRawBoundingBox() const + 13
  1  CoreText                       0x2db69bcf TBaseFont::CalculateFontMetrics(bool) const + 110
  2  CoreText                       0x2db69bcf TBaseFont::CalculateFontMetrics(bool) const + 110
  3  CoreText                       0x2db76d3f TComponentFont::CalculateFontMetrics(bool) const + 34
  4  CoreText                       0x2db69a15 TBaseFont::InitFontMetrics() const + 44
  5  CoreText                       0x2db69851 TBaseFont::GetStrikeMetrics(float, CGAffineTransform const*, bool) const + 104
  6  CoreText                       0x2db6961f TFont::InitStrikeMetrics() const + 38
  7  CoreText                       0x2db695cd CTFontGetAscent + 92
  8  GraphicsServices               0x321122c5 GSFontEnsureExtraData + 228
  9  GraphicsServices               0x321143dd GSFontGetLatin1LayoutInfo + 44
  10 UIFoundation                   0x34e0f49d -[UIFont(UIFont_AttributedStringDrawing) _getLatin1GlyphMapping:andAdvanceMapping:] + 12
  11 UIFoundation                   0x34de5be7 __NSStringDrawingEngine + 3814
  12 UIFoundation                   0x34deae4b -[NSAttributedString(NSExtendedStringDrawing) boundingRectWithSize:options:context:] + 902
  13 UIKit                          0x2ff24383 -[UILabel _updateScaledMetricsForRect:] + 594
  14 UIKit                          0x2fcc8b9f -[UILabel setAdjustsFontSizeToFitWidth:] + 206
  15 PhotosUI                       0x33d620df -[PUFlatWhiteInterfaceTheme configureAlbumListSubtitleLabel:]
  16 PhotosUI                       0x33cb82f5 +[PUAlbumListCellContentView _updateLabelGlobalCachedSizes]
  17 libobjc.A.dylib                0x37803271 _class_initialize + 572
  18 libobjc.A.dylib                0x3780a7cf lookUpImpOrForward + 130
  19 libobjc.A.dylib                0x3780302b _class_lookupMethodAndLoadCache3 + 34
  20 libobjc.A.dylib                0x37802df9 _objc_msgSend_uncached + 24
  21 PhotosUI                       0x33cb720d -[PUAlbumListTableViewController tableView:cellForRowAtIndexPath:]
  22 UIKit                          0x2fd61315 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 408
  23 UIKit                          0x2fd096cd -[UITableView _updateVisibleCellsNow:] + 1800
  24 UIKit                          0x2fd08ef1 -[UITableView layoutSubviews] + 184
  25 UIKit                          0x2fc2f353 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 346
  26 QuartzCore                     0x2f8b5943 -[CALayer layoutSublayers] + 142
  27 QuartzCore                     0x2f8b1167 CA::Layer::layout_if_needed(CA::Transaction*) + 350
  28 UIKit                          0x2fc44231 -[UIView(Hierarchy) layoutBelowIfNeeded] + 532
  29 PhotosUI                       0x33d7aca9 -[PUAbstractAlbumListViewController viewDidLayoutSubviews]
  30 UIKit                          0x2fc2f429 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 560
  31 QuartzCore                     0x2f8b5943 -[CALayer layoutSublayers] + 142
  32 QuartzCore                     0x2f8b1167 CA::Layer::layout_if_needed(CA::Transaction*) + 350
  33 QuartzCore                     0x2f8b0ff9 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 16
  34 QuartzCore                     0x2f8b0a0d CA::Context::commit_transaction(CA::Transaction*) + 228
  35 QuartzCore                     0x2f8b081f CA::Transaction::commit() + 314
  36 QuartzCore                     0x2f8aa54d CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 56
  37 CoreFoundation                 0x2d475f69 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 20
  38 CoreFoundation                 0x2d4738f7 __CFRunLoopDoObservers + 286
  39 CoreFoundation                 0x2d473c43 __CFRunLoopRun + 738
  40 CoreFoundation                 0x2d3de471 CFRunLoopRunSpecific + 524
  41 CoreFoundation                 0x2d3de253 CFRunLoopRunInMode + 106
  42 GraphicsServices               0x321182eb GSEventRunModal + 138
  43 UIKit                          0x2fc93845 UIApplicationMain + 1136
  44 Celly                          0x0000cde3 main (main.m:17)
  </code></pre>