gpt4 book ai didi

ios - 创建 MTLTexture 对象时出现无法识别的选择器错误

转载 作者:行者123 更新时间:2023-11-29 00:43:21 37 4
gpt4 key购买 nike

我使用以下代码创建了一个 MTLTexture 对象(为清楚起见,仅列出了部分代码)。

int tmpbuf[4096]
id<MTLDevice> device = MTLCreateSystemDefaultDevice();
MTLTextureDescriptor* desc = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat: MTLPixelFormatA8Unorm width: 64 height:64 mipmapped: NO];
id<MTLTexture> input_texture = [device newTextureWithDescpriptor:desc];

//memory for the texture
MTLOrigin texture_origin = { 0, 0, 0};
MTLSize texture_size = {64, 64, 0};
MTLRegion texture_region = {texture_origin, texture_size};
[input_texture replaceRegion: texture_region mipmaplevel: 0 withBytes: tmpbuf bytesPerRow: 64 ];

运行代码时:

id<MTLTexture> input_texture    = [device newTextureWithDescpriptor:desc];

报告了[MTLIGAccelDevice newTextureWithDescriptor:]:无法识别的选择器发送到实例 0x7fd0a3012200 的错误。此代码是在 OS X 系统上编译和运行的。我不知道为什么会发生此错误。

最佳答案

确保首先在第一行末尾添加一个;,然后为第三个MTLSize 参数添加一个非空值。下面的代码片段在我的 OS X 10.11.6 机器上编译得很好。

    int tmpbuf[4096];
id<MTLDevice> device = MTLCreateSystemDefaultDevice();
MTLTextureDescriptor* desc = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat: MTLPixelFormatA8Unorm width: 64 height:64 mipmapped: NO];
id<MTLTexture> input_texture = [device newTextureWithDescriptor:desc];
MTLOrigin texture_origin = { 0, 0, 0};
MTLSize texture_size = {64, 64, 1};
MTLRegion texture_region = {texture_origin, texture_size};
[input_texture replaceRegion:texture_region mipmapLevel:0 withBytes:tmpbuf bytesPerRow:64];

关于ios - 创建 MTLTexture 对象时出现无法识别的选择器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38950948/

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