title: iOS Crash when repeatedly calling Vision with CVPixelBuffer
body: <p>I have an application that repeatedly tells a <code>VNImageRequestHandler</code> object to perform a <code>VNDetectFaceRectanglesRequest</code> from a <code>CVPixelBuffer</code> which is delivered to me from the iOS Camera.</p>
  
  <p>I frequently see crashes from Fabric that look like this:</p>
  
  <p><code>#0 Crashed: com.apple.main-thread</code></p>
  
  <p><code>EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000000</code></p>
  
  <p><code>0  CoreVideo</code></p>
  
  <p><code>CVPixelBufferGetWidth + 20</code></p>
  
  <p>I already try and validate my <code>CVPixelBuffer</code> using an extension before I pass it to vision like this:</p>
  
  <pre><code>var isValid: Bool {
      let cvBufferWidth = CVPixelBufferGetWidth(self)
      let cvBufferHeight = CVPixelBufferGetHeight(self)
      let size = CVPixelBufferGetDataSize(self)
      let bytesPerRow = CVPixelBufferGetBytesPerRow(self)
  
      guard cvBufferWidth &gt; 0 &amp;&amp; cvBufferHeight &gt; 0 &amp;&amp; size &gt; 0 &amp;&amp; bytesPerRow &gt; 0 else {
          return false
      }
  
      return true
  }
  </code></pre>
  
  <p>I also only ever process one <code>CVPixelBuffer</code> at a time (Apple has a sample project that said this is best practice in the comments).</p>
  
  <p>What should I do? I can't seem to shake this bug!! Should I lock the <code>CVPixelBuffer</code>'s base address? </p>
  
  <p><code>CVPixelBufferLockBaseAddress(self, CVPixelBufferLockFlags.readOnly)</code></p>
  
  <p>Apple says don't do this if using the GPU and I know vision will use the GPU in some cases.</p>
  
  <p>Any ideas?</p>