title: Metal craches on MTLDevice.makeBuffer(bytes:length:options:)
body: <p>I was working with a simple Metal program for iOS with the book <em>Metal Programming Guide</em>, but the <code>makeBuffer(bytes:length:options:)</code> does not work as stated in the book.</p>
  
  <p>The related code below</p>
  
  <pre><code>let vertexData: [Float] = [
      0.0,  0.5,  0.0,
      -1.0, -0.5,  0.0,
      1.0,  -0.5,  0.0
      ]
  
  let dataSize = vertexData.count * MemoryLayout.size(ofValue: vertexData[0])
  vertexBuffer = device.makeBuffer(bytes: vertexData, length: dataSize,
      options: [.storageModePrivate]) // error on this line
  
  ...
  
  let renderEncoder = commandBuffer?.makeRenderCommandEncoder(
      descriptor: renderPassDescriptor)
  renderEncoder?.setVertexBuffer(vertexBuffer, offset: 0, index: 0)
  // skipping other setups
  renderEncoder?.endEncoding()
  </code></pre>
  
  <p>will cause a crash during runtime, and here is the error log:</p>
  
  <blockquote>
    <p><code>-[MTLDebugDevice newBufferWithBytes:length:options:]:494: failed assertion  `storageModePrivate incompatible with ...WithBytes variant of newBuffer'</code></p>
  </blockquote>
  
  <p>However, if I use <code>[]</code> as the argument for <code>options</code> in <code>makeBuffer(bytes:length:options:)</code>, the program will work fine:</p>
  
  <pre><code>vertexBuffer = device.makeBuffer(bytes: vertexData, length: dataSize,
      options: []) // this will run
  </code></pre>
  
  <p>But why is this the case? </p>