gpt4 book ai didi

ios - MTLBuffer 内容导致 EXC_BAD_ACCESS

转载 作者:可可西里 更新时间:2023-11-01 01:20:06 25 4
gpt4 key购买 nike

我创建了一个由浮点值数组填充的缓冲区。不幸的是,当我尝试查询其 contents() 属性时(当我试图调试问题时),我得到了 EXC_BAD_ACCESS。这是代码:

let inputData  = [Float32](repeatElement(5, count: 16384)) // Declaration

// Declaration of the buffer and filling contents...
inputBuffer = device.makeBuffer(bytes: inputData, length: MemoryLayout<Float32>.size * inputData.count, options: MTLResourceOptions())

// Crash occurs here:
let contents = inputBuffer.contents().load(as: [Float32].self)

我想知道为什么会发生崩溃。其他类似的缓冲区声明工作正常,所以我猜这可能是访问内容的问题。

最佳答案

要使用load 方法访问数组内容,您需要指定数组元素类型(以及可选的偏移量)。例如:

let firstElement = inputBuffer.contents().load(fromByteOffset: 0, as: Float.self)

等等。您试图将第一个元素作为 [Float] 加载,这可能会解释崩溃。

关于ios - MTLBuffer 内容导致 EXC_BAD_ACCESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44342966/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com