title: On screen recording video crashing in iOS 8
body: <p>Here are the description of my code</p>
  
  <p>Mainly crash getting on these two line.</p>
  
  <p>BOOL success = [_avAdaptor appendPixelBuffer:pixelBuffer withPresentationTime:time];
                  if (!success) {
                      NSLog(@"Warning: Unable to write buffer to video");
                  }</p>
  
  <pre><code>if (dispatch_semaphore_wait(_frameRenderingSemaphore, DISPATCH_TIME_NOW) != 0) {
      return;
  }
  dispatch_async(_render_queue, ^{
      if (![_videoWriterInput isReadyForMoreMediaData]) return;
  
      if (!self.firstTimeStamp) {
          self.firstTimeStamp = _displayLink.timestamp;
      }
      CFTimeInterval elapsed = (_displayLink.timestamp - self.firstTimeStamp);
      CMTime time = CMTimeMakeWithSeconds(elapsed, 1000);
  
      CVPixelBufferRef pixelBuffer = NULL;
      CGContextRef bitmapContext = [self createPixelBufferAndBitmapContext:&amp;pixelBuffer];
  
      if (self.delegate) {
          [self.delegate writeBackgroundFrameInContext:&amp;bitmapContext];
      }
      // draw each window into the context (other windows include UIKeyboard, UIAlert)
      // FIX: UIKeyboard is currently only rendered correctly in portrait orientation
      dispatch_sync(dispatch_get_main_queue(), ^{
          UIGraphicsPushContext(bitmapContext); {
              for (UIWindow *window in [[UIApplication sharedApplication] windows]) {
                  [window drawViewHierarchyInRect:CGRectMake(0, 0, _viewSize.width, _viewSize.height) afterScreenUpdates:NO];
              }
          } UIGraphicsPopContext();
      });
  
      // append pixelBuffer on a async dispatch_queue, the next frame is rendered whilst this one appends
      // must not overwhelm the queue with pixelBuffers, therefore:
      // check if _append_pixelBuffer_queue is ready
      // if it’s not ready, release pixelBuffer and bitmapContext
      if (dispatch_semaphore_wait(_pixelAppendSemaphore, DISPATCH_TIME_NOW) == 0) {
          dispatch_async(_append_pixelBuffer_queue, ^{
              **BOOL success = [_avAdaptor appendPixelBuffer:pixelBuffer withPresentationTime:time];
              if (!success) {
                  NSLog(@"Warning: Unable to write buffer to video");
              }**
              CGContextRelease(bitmapContext);
              CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
              CVPixelBufferRelease(pixelBuffer);
  
              dispatch_semaphore_signal(_pixelAppendSemaphore);
          });
      } else {
          CGContextRelease(bitmapContext);
          CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
          CVPixelBufferRelease(pixelBuffer);
      }
  
      dispatch_semaphore_signal(_frameRenderingSemaphore);
  });
  </code></pre>
  
  <p>Also error description is </p>
  
  <blockquote>
    <p>thread #34: tid = 0x4aefc, 0x00000001958952bc
    libsystem_platform.dylib<code>_platform_memmove + 108, queue =
    'ASScreenRecorder.append_queue', stop reason = EXC_BAD_ACCESS (code=1,
    address=0x109c60000)
        frame #0: 0x00000001958952bc libsystem_platform.dylib</code>_platform_memmove + 108
        frame #1: 0x0000000183c32004 CoreMedia<code>FigNEAtomWriterAppendData + 92.
        frame #2: 0x0000000183c31f8c CoreMedia</code>sbufAtom_appendAtomWithMemoryBlock + 104
        frame #3: 0x0000000183c2f78c CoreMedia<code>sbufAtom_createSerializedDataForPixelBuffer + 588
        frame #4: 0x0000000183c2f4b8 CoreMedia</code>FigRemote_CreateSerializedAtomDataForPixelBuffer + 288
        frame #5: 0x0000000185a6af3c MediaToolbox<code>remoteWriter_AddPixelBuffer + 140
        frame #6: 0x0000000181bcebd4 AVFoundation</code>-[AVFigAssetWriterTrack addPixelBuffer:atPresentationTime:error:] + 176
        frame #7: 0x0000000181bca848 AVFoundation<code>-[AVAssetWriterInputWritingHelper
    appendPixelBuffer:withPresentationTime:] + 124
        frame #8: 0x0000000181bc82fc AVFoundation</code>-[AVAssetWriterInput _appendPixelBuffer:withPresentationTime:] + 88
        frame #9: 0x0000000181bcdb40 AVFoundation<code>-[AVAssetWriterInputPixelBufferAdaptor
    appendPixelBuffer:withPresentationTime:] + 104
        frame #10: 0x00000001000f45e0 Island Guide Aruba</code>__35-[ASScreenRecorder
    writeVideoFrame]_block_invoke192(.block_descriptor=) +
    132 at ASScreenRecorder.m:301
        frame #11: 0x00000001005b0fd4 libdispatch.dylib<code>_dispatch_call_block_and_release + 24
        frame #12: 0x00000001005b0f94 libdispatch.dylib</code>_dispatch_client_callout + 16
        frame #13: 0x00000001005bbdb8 libdispatch.dylib<code>_dispatch_queue_drain + 780
        frame #14: 0x00000001005b42c4 libdispatch.dylib</code>_dispatch_queue_invoke + 132
        frame #15: 0x00000001005be5d4 libdispatch.dylib<code>_dispatch_root_queue_drain + 772
        frame #16: 0x00000001005c0248 libdispatch.dylib</code>_dispatch_worker_thread3 + 132     frame #17:
    0x000000019589d21c libsystem_pthread.dylib`_pthread_wqthread + 816</p>
  </blockquote>
  
  <p>========================================================================</p>