title: iPhone: SIGSEGV occurs seemingly randomly (ViewDidLoad, setFont, etc.) on device, never in simulator
body: <p>First, thanks in advance for taking the time to read through this.  I have been searching for an answer to this issue for a few days but I cannot seem to find what I am looking for.  I know that SIGSEGV errors (or EXEC_BAD_ACCESS faults) are usually caused by memory management issues but after hours of looking at the code, I can't seem to find an error.  The static analyzer hasn't found anything either.</p>
  
  <p>As the title says, this error only occurs on the device (never in the simulator) and doesn't happen every time the given view loads.  Obviously this means that I can't use NSZombie to debug what is going wrong.</p>
  
  <p>Let's start with the crash dump log:</p>
  
  <pre><code>0 myApp 0x00036659 +[TFCrashHandler backtrace] + 428
  1 myApp 0x00036a6f TFSignalHandler + 54
  2 libsystem_c.dylib 0x32f48539 _sigtramp + 48
  3 UIKit 0x365701df -[UIView(Rendering) setNeedsDisplay] + 86
  4 UIKit 0x36598269 -[UILabel setFont:] + 232
  5 myApp 0x000190eb +[BruUISettings applyLabelDetailStyle:] (BruUISettings.m:130)
  6 myApp 0x0001aa57 -[ActiveChallengeViewController viewDidLoad] (ActiveChallengeViewController.m:115)
  7 UIKit 0x365a57ff -[UIViewController view] + 166
  8 UIKit 0x365b1c39 -[UIViewController contentScrollView] + 24
  9 UIKit 0x365b1aa9 -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] + 36
  10 UIKit 0x365b198f -[UINavigationController _layoutViewController:] + 34
  11 UIKit 0x365b115b -[UINavigationController _startTransition:fromViewController:toViewController:] + 318
  12 UIKit 0x365b0f53 -[UINavigationController _startDeferredTransitionIfNeeded] + 250
  13 UIKit 0x365a5673 -[UINavigationController pushViewController:transition:forceImmediate:] + 806
  14 UIKit 0x365a5349 -[UINavigationController pushViewController:animated:] + 36
  15 myApp 0x00015dc7 -[ChallengesHomeViewController tableView:didSelectRowAtIndexPath:] (ChallengesHomeViewController.m:325)
  16 UIKit 0x3661f565 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 944
  17 UIKit 0x36697ce7 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 158
  18 Foundation 0x31f7a943 __NSFireDelayedPerform + 414
  19 CoreFoundation 0x34ab1a63 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 14
  20 CoreFoundation 0x34ab16c9 __CFRunLoopDoTimer + 364
  21 CoreFoundation 0x34ab029f __CFRunLoopRun + 1206
  22 CoreFoundation 0x34a334dd CFRunLoopRunSpecific + 300
  23 CoreFoundation 0x34a333a5 CFRunLoopRunInMode + 104
  24 GraphicsServices 0x351a7fed GSEventRunModal + 156
  25 UIKit 0x3659a743 UIApplicationMain + 1090
  26 myApp 0x000026c5 main (main.m:13)
  27 myApp 0x0000265c start + 52
  </code></pre>
  
  <p>Note, I am using TestFlight from testflightapp.com and it is there exception handler at the top of the stack.</p>
  
  <p>Here is the code that is creating and pushing the view controller in question:</p>
  
  <pre><code>CDAcceptedChallenge *challengeAtIndex = [self.activeChallenges objectAtIndex:[indexPath row]];
  ActiveChallengeViewController *view = [[ActiveChallengeViewController alloc] initWithNibName:@"ActiveChallengeViewController" 
                                                                                        bundle:nil 
                                                                               activeChallenge:challengeAtIndex];
  view.leaveChallengeTarget = self;
  
  [self.navigationController pushViewController:view animated:YES];
  [view release];
  </code></pre>
  
  <p>This code is running inside of a didSelectRowAtIndex method, if that matters at all.  This view controller has a bunch of member variables and IBOutlets which reference objects in the nib but here are the ones that correlate to the object mentioned in this error:</p>
  
  <p>in .h:</p>
  
  <pre><code>UILabel *helpLabel;
  ...
  @property (nonatomic, retain) IBOutlet UILabel *helpLabel;
  </code></pre>
  
  <p>in .m:</p>
  
  <pre><code>@synthesize helpLabel;
  </code></pre>
  
  <p>I am positive that helpLabel is bound to the correct object in the nib because it does get the correct styling when this doesn't blow up. Next, here is the init method for this view controller:</p>
  
  <pre><code>self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  
  if (self) 
  {
      self.activeChallenge = inActiveChallenge;
  }
  return self;
  </code></pre>
  
  <p>Here is the viewDidLoad method where we will sometimes see the crash (bolded).  Note, there is a lot going on here but nothing touches the self.helpLabel which is what eventually triggers the crash.</p>
  
  <pre><code>[super viewDidLoad];
  [self.navigationController setNavigationBarHidden:FALSE];
  self.navigationItem.title = @"Details";
  
  // overlay disclosure creation
  self.overlayDisclosure = [CustomColoredDisclosureIndicator accessoryWithColor:self.challengeNameLabel.textColor];
  self.overlayDisclosure.highlightedColor = [UIColor whiteColor];
  [self.overlayDisclosure addTarget:self action:@selector(overlayViewButtonClick:) forControlEvents:UIControlEventTouchUpInside];
  [self.view addSubview:self.overlayDisclosure];
  
  [[BruNotificationManager instance] registerForTabUpdated:[[[BruCallback alloc] initWithTarget:self 
                                                                                   andCallback:@selector(tabUpdated:)] autorelease]];
  [[BruNotificationManager instance] registerForActiveChallengesUpdated:[BruCallback buildFromObject:self 
                                                                                         andCallback:@selector(challengesUpdatedLocally)]];
  [[BruNotificationManager instance] registerForEarnedRewardsUpdated:[BruCallback buildFromObject:self 
                                                                                      andCallback:@selector(rewardsUpdatedLocally:)]];
  
  [super refreshEarnedRewardsForChallenge:self.activeChallenge.challenge.identifier];
  [super refreshTabForChallenge:self.activeChallenge.challenge.identifier];
  
  UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd 
                                                                             target:self 
                                                                             action:@selector(addBeer)];
  self.navigationItem.rightBarButtonItem = addButton;
  [addButton release];
  
  // Request that the object download its image
  BruCallback *imageCallback = [BruCallback buildFromObject:self andCallback:@selector(imageRequestCompleted:withData:)];
  self.challengeImageView.image = [self.activeChallenge.challenge retrieveImage:self.bruConnection withCallback:imageCallback];
  
  // Create our help label
  **[BruUISettings applyLabelDetailStyle:self.helpLabel];**
  self.helpLabel.textColor = AccentSecondaryColor;
  
  self.overlayView.alpha = [BruUISettings standardOverlayViewAlpha];
  
  [BruUISettings applyTableStyle:self.rewardsTable];
  [BruUISettings applyScrollViewStyle:self.scrollView];
  
  self.needToUpdateTab = YES;
  self.needToUpdateRewards = YES;
  self.needToUpdateChallenge = NO;
  </code></pre>
  
  <p>Here is a trimmed down version of the viewDidUnload method, though I don't see why it would matter in this case:</p>
  
  <pre><code>...
  self.helpLabel = nil;
  ...
  
  [super viewDidUnload];
  </code></pre>
  
  <p>Finally, my [BruUISettings applyLabelDetailStyle] is a method that applies a centralized style to my label.  There are a bunch of places in my code that use this function so that I can change all of the styles for those labels by just changing the one function.</p>
  
  <pre><code>+ (void) applyLabelDetailStyle:(UILabel *)inLabel
  {
      inLabel.font = [UIFont fontWithName:@"Helvetica Neue" size:12.0];
      inLabel.textColor = [UIColor darkGrayColor];
      inLabel.backgroundColor = [UIColor clearColor];
  }
  </code></pre>
  
  <p>Any thoughts as to what could be happening here would be greatly appreciated.  Thanks again.</p>