iOS 8.3-金属,展开一个可选值时发现为零 [英] iOS 8.3 - Metal, found nil while unwrapping an Optional Value

查看:129
本文介绍了iOS 8.3-金属,展开一个可选值时发现为零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Apple发布iOS 8.3之前,我的代码可以正常工作,但是由于更新的XCode抱怨找到了一个nil值,即使我的值都不为nil(我在调试时对此进行了验证).

Before Apple released iOS 8.3 my code worked, however since the updating XCode complains that a nil value is found, even though none of my values are nil (I validated this when debugging).

出于理智,我重新编写了程序,使用Metal渲染了一个简单的三角形到屏幕上,但是抛出了同样的错误.我有一个由3个顶点组成的数组,然后将其乘以数组的大小即可得到缓冲区的大小,并传入OptionCPUCacheModeDefault,因为我认为传递nil参数可能是导致问题的原因.

For sanity, I re-wrote my program to render a simple triangle to the screen with Metal, but the same error is thrown. I have an array of 3 vertices, I then multiply that by the array size to get the size of the buffer and pass in OptionCPUCacheModeDefault as I thought passing a nil parameter may have been what was causing my problem.

// Test array of vertices
let ASVertices:[Float] = [
    0.0, 1.0, 0.0,
    -1.0, -1.0, 0.0,
    1.0, -1.0, 0.0
]

// Other Metal init code...

// Set the buffers
let dataSize = ASVertices.count * sizeofValue(ASVertices[0])
vertexBuffer = ASDevice.newBufferWithBytes(ASVertices, 
                              length: dataSize, 
                              options: MTLResourceOptions.OptionCPUCacheModeDefault)

当我调试时,我可以看到dataSize是预期的36(9 * 4),所以我对为什么得到fatal error when unwrapping an optional value感到很困惑.我知道错误是不言自明的,但是上面打印的代码是堆栈跟踪显示正在引发的异常的地方,但是我看不到那里的nil值.是什么原因造成的?

When I debug, I can see that dataSize is 36 (9*4) as expected, so I am fairly stumped as to why I am getting a fatal error when unwrapping an optional value. I know that error is self explanatory but the code printed above is where the stack trace shows the exception being raised, but I see no nil values there. What could be causing this?

推荐答案

当连接到Xcode时,金属不能真正与iOS 8.3一起使用.现在,禁用GPU帧捕获,并提交雷达.

Metal doesn't really work with iOS 8.3, when connected to Xcode. For now, disable GPU Frame Capture, and file a radar.

这篇关于iOS 8.3-金属,展开一个可选值时发现为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆