title: wait_fences: failed to receive reply: 10004003 (Again)
body: <p>Another cry for help about this warning.</p>
  
  <p>First of all I have looked at every and all questions on here elsewhere and none seem to fit my situation.  It has nothing to do with Alert boxes and resigning as first responder, nor performing any animation before views get displayed.  My problem occurs when instantiating a UIView based custom keyboard.</p>
  
  <p>Secondly, I believe that I can make the warning appear/disappear at will.  I am just very confused as to why, so I am looking more for an explanation than a solution. </p>
  
  <p>There is too much code to post here, so I'll just give an outline of what is going on:</p>
  
  <blockquote>
    <p>The ViewController "Calc" instantiates a custom UIView based "DataView" in the VC's loadView method, and then adds it as a sub view of the VC.</p>
    
    <p>The "DataView" instantiates a custom UITextField based "TextFieldKPD" in the DataView's init method</p>
    
    <p>The "TextField" instantiates a custom UIView based "KeyPad" in the TextField's init method, and assigns that KeyPad to the TextField's inputView.</p>
    
    <p>The "KeyPad" creates 13 UIButtons of type UIButtonTypeCustom, reads in and assigns a "pressed" and "not pressed" image for each button, as well as setting actions for the buttons.  It then adds each button as a subview of itself.  (By controlling when in the UIView lifecycle  of the KeyPad that this construction occurs, is how I can effect the wait_fences warning: see below.)</p>
  </blockquote>
  
  <p>The "Calc" ViewController is the one that is initially presented to the user. I have tracked down the wait_fences warning as occurring after the end of the Calc's viewDidLayoutSubViews method and before its viewDidAppear method is called.  Note that the KeyPad is not visible when the Calc is displayed.</p>
  
  <p>I appear to be able to control the action of the wait_fences warning by changing how the Keypad is constructed:</p>
  
  <ul>
  <li><p>If the UIButtons are instantiated and added as subviews in the init method of the KeyPad, then I will get the warning, once and once only.</p></li>
  <li><p>If, instead, the buttons are instantiated and added in the KeyPad's layoutSubViews method, then the warning does not appear.  (But the KeyPad doesn't effectively get constructed until I tap on the TextField - still, no wait_fences warning then either)</p></li>
  </ul>
  
  <p>There is no animation or anything in Calc's loadView.  It is instantiate and assign all the way down.</p>
  
  <p>So any comments on this version of wait_fences?  </p>
  
  <p><strong>EDIT 1, Jan 30th - Now With Even More Confusion!</strong></p>
  
  <p>I was bored this morning so I decided to play with my code to see if I could better isolate the generation of the warning. I narrowed it down to the following, totally useless code that with which I can now trigger the warning:</p>
  
  <pre><code>-(void)loadImages
  {
      UIImage* image;
  
      for(int i=0; i&lt;16; i++) {
          image = [UIImage imageNamed:@"StupidFileNameThatDoesNotExist"];
      }
  }
  </code></pre>
  
  <p>If I perform <code>[self loadImages]</code> in the init method of <code>KeyPad</code> then the warning appears.  But this code does nothing as the file does not exist.  I believe that if the loop counter is small enough that the warning does go away, but I haven't qualified a lower limit. </p>
  
  <p>If I replace the actual loading of the image with </p>
  
  <p><code>[UIImage imageWithContentsOfFile:@"StupidFileNameThatDoesNotExist"]</code> </p>
  
  <p>and still call the method during the <code>KeyPad</code> init, then I do not seem to get the warning.  One obvious difference between these two ways of loading the image is that <code>imageNamed</code> caches the image internally.</p>
  
  <p>So I am leaning towards George's answer that it is an internal Apple screw up. </p>
  
  <p><strong>Edit 2, Feb 1 - Its a warning Jim, but not as we know it</strong></p>
  
  <p>So I convinced myself that it was the caching in the UIImage class that was obviously causing the issue.  What to do about it?  Well write my own image cache of course!!</p>
  
  <p>So I started plugging away, rip out that code that attempted to load invalid images and got the point where I generated the file names I needed and passed them to my cache controller.  So to verify that things were starting to come together, within the cache controller, I generated a NSLog message for each attempt to cache an image - nothing more - just log the file name.</p>
  
  <p>And guess what - I get the stupid warning again.  For doing no actual work at all.</p>
  
  <p>I can only conclude that there is some sort of internal iOS race condition that I am triggering when I cram extra code into the init method of <code>KeyPad</code>.  And that there is nothing I can do to mitigate it.  All I can do is hope that this warning is benign.</p>
  
  <p><strong>Edit 3, Hamlet Act 1 scene 4: Something is rotten in the state of Denmark</strong></p>
  
  <p>Keeping the same code as in Edit 2, I commented out the NSLog statement.  And the warning went away.  I put it back, and the warning appears.</p>
  
  <p>So the code I have is:</p>
  
  <pre><code>-(void)loadImages
  {
      // Iterate over button definitions and cache the required images
      for(int i=0; i&lt;numKeys; i++) {
  
          if (![imageCache imageExistsForTag:keyTags[i]]) {
              [imageCache addImageFile:[NSString stringWithFormat:@"%s_NP.png",keyNames[i]] forTag:keyTags[i]];
          }
  
          if (![imageCache imageExistsForTag:keyTags[i]+pressedOffset]) {
              [imageCache addImageFile:[NSString stringWithFormat:@"%s_P.png",keyNames[i]] forTag:keyTags[i]+pressedOffset];
          }
  
      }
  
  }
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>-(void)addImageFile:(NSString*)imageFile forTag:(int)tag
  {
      NSLog(@"Adding tag:%d for file %@", tag, imageFile);
  }
  </code></pre>
  
  <p>With that NSLog statement controlling the appearance of the warning.</p>
  
  <p><strong>Edit 4, Feb 2 - Welcome to the Temple of Doom</strong></p>
  
  <p>Taking Allen's comments to heart I rebuilt my keyboard as a XIB and loaded that instead of manually trying to build the view.  Of course that didn't fix anything.  I had hoped that the Nib loading would happen outside of what ever it is that is causing the problem.</p>
  
  <p>My gut feeling is that I am butting up against a race condition within the loadView of Calc and some internal iOS activity.  If I do too much work inside loadView then I cross the line  and trip a wait_fences warning.  And that the keyboard is a symptom and not the underlying cause.  IE it could have been any activity, it was just that the keyboard work was the last thing I did before the warning started appearing.  I just wish that I actually knew what the constraints were that I was actually crossing and not stumbling around in the dark.</p>