title: Crash in actionForLayer:forKey:
body: <p>I have a cryptic EXC_BAD_ACCESS when changing some UILabel's frame. The crash is random, usually I have to repeat the conditions for several minutes.</p>
  
  <p>Enabling NSZombies, as well as other memory debug flags (NSDebugEnabled, MallocStackLogging), doesn't help, the crash stills stays as opaque : just a BAD_ACCESS with no message in the console. The target seems correct and alive, so it doesn't look like a deallocated memory problem.</p>
  
  <p>To get some more info, I subclassed UILabel and rewrote the crashing function :</p>
  
  <pre><code>@implementation TestUILabel
  - (id&lt;CAAction&gt;)actionForLayer:(CALayer *)layer forKey:(NSString *)event {
      return [super actionForLayer:layer forKey:event];
  }
  @end
  </code></pre>
  
  <p>It crashes in the super's method, but on inspection everything seems correct (printing retainCount for 'self' and 'layer' gives respectively 3 and 2) :</p>
  
  <blockquote>
    <p>(gdb) po self</p>
    
    <p>&lt; TestUILabel: 0x6ac2800;
    baseClass = UILabel; frame = (173 174;
    0 0); text = '54 m²'; opaque = NO;
    autoresize = LM+TM;
    autoresizesSubviews = NO;
    userInteractionEnabled = NO;
    animations = {
    position=&lt; CABasicAnimation:
    0xe07ba60>; }; layer = &lt; CALayer:
    0xbf1b950>></p>
    
    <p>(gdb) po event</p>
    
    <p>bounds</p>
    
    <p>(gdb) po layer</p>
    
    <p>&lt; CALayer:0xbf1b950;
    position = CGPoint (173 174); bounds =
    CGRect (0 0; 0 0); delegate =
    &lt; TestUILabel: 0x6ac2800; baseClass =
    UILabel; frame = (173 174; 0 0); text
    = '54 m²'; opaque = NO; autoresize = LM+TM; autoresizesSubviews = NO;
    userInteractionEnabled = NO;
    animations = {
    position=&lt; CABasicAnimation:
    0xe07ba60>; }; layer = &lt; CALayer:
    0xbf1b950>>; contents = &lt; CGImage
    0xe04ed60>; opacity = 1; animations =
    [position=&lt; CABasicAnimation:
    0xe07ba60>]></p>
  </blockquote>
  
  <p>Did someone get a similar problem ? Or have any ideas where this could come from ?</p>
  
  <p>Thanks in advance !</p>
  
  <p>Edit:
  here's the complete crash backtrace :</p>
  
  <blockquote>
    <p>Thread 1, Queue :<br>
    com.apple.main-thread<br>
    #0   0x00459b2c in -[UIView(CALayerDelegate) actionForLayer:forKey:] ()<br>
    #1   0x00eaaac7 in -[CALayer actionForKey:] ()<br>
    #2   0x00ea80fe in actionForKey(CALayer*,
    CA::Transaction*, NSString*) ()<br>
    #3   0x00ea8066 in beginChange(CALayer*, CA::Transaction*, unsigned int,
    objc_object*&amp;) ()<br>
    #4   0x00eaba3a in CALayerSetPosition(CALayer*,
    CA::Vec2 const&amp;, bool) ()<br>
    #5   0x00eab8b5 in -[CALayer setPosition:] ()<br>
    #6   0x00eab7cc in -[CALayer setFrame:] ()<br>
    #7   0x0045739d in -[UIView(Geometry) setFrame:] ()<br>
    #8   0x00542a68 in -[UILabel setFrame:] ()<br>
    #9   0x0000a97f in -[MosaicElementView setupWithAdvert:] at
    /Users/eino/Prog/AJ/Classes/Search/SubViews/MosaicElementView.m:30<br>
    #10  0x00079cb9 in -[SearchResultsViewController setupElement:withCell:indexPath:actualIndex:]
    ()<br>
    #11  0x000797a2 in -[SearchResultsViewController tableView:cellForRowAtIndexPath:] ()<br>
    #12  0x004957fa in -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:]
    ()<br>
    #13  0x0048b77f in -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] ()<br>
    #14  0x004a0450 in -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] ()<br>
    #15  0x00498538 in -[UITableView layoutSubviews] ()<br>
    #16  0x00eb0451 in -[CALayer layoutSublayers] ()<br>
    #17  0x00eb017c in CALayerLayoutIfNeeded ()<br>
    #18  0x00ea937c in CA::Context::commit_transaction(CA::Transaction*)
    ()<br>
    #19  0x00ea90d0 in CA::Transaction::commit() ()<br>
    #20  0x00ed97d5 in CA::Transaction::observer_callback(__CFRunLoopObserver*,
    unsigned long, void*) ()<br>
    #21  0x017e9fbb in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__
    ()<br>
    #22  0x0177f0e7 in __CFRunLoopDoObservers ()<br>
    #23  0x01747bd7 in __CFRunLoopRun ()<br>
    #24  0x01747240 in CFRunLoopRunSpecific ()<br>
    #25  0x01747161 in CFRunLoopRunInMode ()<br>
    #26  0x01e7d268 in GSEventRunModal ()<br>
    #27  0x01e7d32d in GSEventRun ()<br>
    #28  0x0043042e in UIApplicationMain ()<br>
    #29  0x000021fe in main at /Users/eino/Prog/AJ/main.m:11  </p>
  </blockquote>
  
  <p>The crasing line from frame 9 is basically just the frame change :</p>
  
  <pre><code>labelPrice.frame = rect;
  </code></pre>
  
  <p>with rect being a correct CGRect (106, 143, 86, 22).</p>