ios - ios 11.4 上的 SceneView hittest 崩溃,在 iOS 12+ 上运行
问题描述
我在 iOS 11.4 上遇到 m_sceneView.hittest(...) 函数崩溃。相同的代码在 iOS 12+ 上运行!
代码如下所示:
func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) {
guard m_sceneView.session.currentFrame != nil else {return}
DispatchQueue.main.async(execute: {
if let camera = self.m_sceneView.session.currentFrame?.camera,
case .normal = camera.trackingState {
let results = self.m_sceneView.hitTest(self.m_sceneView.center,
options: [SCNHitTestOption.searchMode: 2])
guard let result = results.first else {
print("No Hittest results received")
return
}
// do something with the hittest result !
// ...
// ...
}
})
}
我在 hittest 行上收到“EXC_BAD_ACCESS (code=1, address=0x0)”崩溃。
- 我检查了 self.m_sceneView.center 是否包含有效值
- 我正在检查会话状态(如您在代码中看到的)
- 问题是可重现的。
- 我正在操作的视图是 ARSCNView
任何想法如何解决这个问题?
解决方案
我从苹果人那里得到了一个解决方案。它实际上是在 IOS 12 中解决的 SceneKit API 中的一个错误,但是对于 12 之前的版本有一个解决方法:
let options: [SCNHitTestOption: Any] = [SCNHitTestOption.boundingBoxOnly: true]
let hitResults = scnView.hitTest(p, options: options)
推荐阅读
- c# - 将 [CallerMemberName] 属性与 Func 委托一起使用
- html - 如何为以下场景添加断点?
- django - 通过 git 同步 postgres 数据库
- xml - 无法在 Shell 中解析 XML
- javascript - 即使正文包含不在模式中的参数,findByIdAndUpdate 也不会失败
- node.js - 在nestJs中注入mongodb连接不起作用
- arm - 代码大小比较 Cortex M3:IAR ARM 与 Keil µVision
- cloud-foundry - Cloud Foundry 本地 - 未找到液滴
- c# - 如何使用 LINQ 找到 ±1 ± 2 ± 3 ± ... ± n = k 形式的所有可能组合?
- php - SyntaxError: JSON.parse: JSON 数据的第 1 行第 44498 列的 JSON 数据后出现意外的非空白字符