ios RenderPassDescriptor中未设置渲染目标

fnatzsnv  于 2023-02-20  发布在  iOS
关注(0)|答案(1)|浏览(108)

信号SIGABRT错误:

validateRenderPassDescriptor:611: failed assertion
`No rendertargets set in RenderPassDescriptor.'

下面是我设置MTLRenderPassDescriptor的方法:

guard let currenDrawable: CAMetalDrawable = self.currentDrawable else { return }

let renderPassDescriptor = MTLRenderPassDescriptor()
renderPassDescriptor.colorAttachments[0].texture = currenDrawable.texture
renderPassDescriptor.colorAttachments[0].loadAction = .clear
renderPassDescriptor.colorAttachments[0].clearColor = MTLClearColor(red: 0, green: 0, blue: 0, alpha: 0)            

let renderCommandEncoder = commandBuffer.makeRenderCommandEncoder(descriptor: renderPassDescriptor)

调用makeRenderCommandEncoder()时发生崩溃。
有人知道如何避免崩溃,检查渲染目标是否不存在并中止吗?

vkc1a9a2

vkc1a9a21#

renderPassDescriptor.colorAttachments[0]使用前必须初始化,添加即可

相关问题