Failed assertion `newBufferWithBytesNoCopy:pointer 0x107b78020 is not 4096 byte aligned.'

Here is my code :

colorVBO = device.makeBuffer(bytesNoCopy: &colorVAO, length: MemoryLayout<MetalRenderer_VertexOut>.stride * colorVAO.count, options: .storageModeShared, deallocator: nil)

colorVAO is an array.
how to resolve it ?

This thread should explain the error: https://forums.developer.apple.com/thread/8011

but how to get a page-aligned pointer from an array in swift ?

@008v - Are you having a problem with something in the Metal by Tutorials book?

You don’t just need a page-aligned pointer, the memory has to be page aligned too.

Depending on what you’re doing, I did find this in stack overflow: https://stackoverflow.com/questions/27365905/pointer-memory-alignment-to-16k-in-swift-for-metal-buffer-creation - there’s a project that creates page aligned arrays. But I haven’t used it, and I don’t know if it’s up-to-date

Or, just thinking aloud, and I haven’t tried this - to get rid of the page alignment issue you could set up a new MTLBuffer with the desired capacity and do the work directly in the buffer. (Obviously you wouldn’t be able to append to it in this case.) For example something like (untested):

struct CreatedStruct {
  var value: Float = 0
}
let buffer = device.makeBuffer(length: count * MemoryLayout<CreatedStruct>.stride, options: [])
var pointer = buffer.contents().bindMemory(to: CreatedStruct.self, capacity: count)
for _ in 0..< count {
   pointer.pointee.value = newValue
   pointer = pointer.advanced(by: 1)
}