ios - MTLBuffer 内容导致 EXC_BAD_ACCESS

标签 ios swift buffer metal

我创建了一个由浮点值数组填充的缓冲区。不幸的是,当我尝试查询其 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/

相关文章:

iOS如何减慢特定时长的视频播放速度

iphone - 内存管理如何修复泄漏

swift - swift 中带有可选闭包的参数

javascript - 将 JavaScript 转换为 Python 代码时出现十六进制问题

ios - Azure 移动服务自定义 API 多次调用 SQL SP

ios - 对 UIButton 的 3D Touch 执行操作的最佳方式

ios - 提高 CollectionView 加载速度

ios - 在 iOS 中的自定义 View 中播放视频

jquery - 使用缓冲区中的 drawImage 更新 Canvas 不要使用 drawImage 应用操作

multithreading - Delphi XE线程: how to realize function calling buffer?