在Swift ARKit中显示多行文本时,缓冲区导致先前/过多的GPU错误



我正在构建一个应用程序,我想在目标增强图像上显示多行文本。该程序在少于7行的文本中运行良好,但在超过7行时崩溃。我还注意到,如果一行太长,还会出现相同的错误"由于执行过程中的错误,命令缓冲区的执行被中止。忽略(导致先前/过多的GPU错误)"。

let text = SCNText(string: "this is the first line  n hello this is the second line n hello this is the third line n hello this is the fourth line n hello this is the fifth line n hello this is the sixth line n hello this is the seventh line n hello this is the eigth linesn " , extrusionDepth: 0.1)
//setting the basic properties of text
text.font = UIFont.systemFont(ofSize: 1)
text.flatness = 0.005
text.isWrapped = true
let textNode = SCNNode(geometry: text)
let fontScale: Float = 0.01
textNode.scale = SCNVector3(fontScale, fontScale, fontScale)

//将文本设置为图片上方居中并面向相机

textNode.eulerAngles.x = -.pi/2
centerNode(node: textNode)
//self.sceneView.scene.rootNode.addChildNode(planeNode)
// the text will be centered right above the image
node.addChildNode(textNode)
// create a plane node as the background of the text
let textWidth = text.boundingBox.max.x - text.boundingBox.min.x
let textHeight = text.boundingBox.max.y - text.boundingBox.min.y
let plane = SCNPlane(width: CGFloat(textWidth), height: CGFloat(textHeight))
plane.firstMaterial?.transparency = 0.5
plane.firstMaterial?.diffuse.contents = UIColor.black
let planeNode = SCNNode(geometry: plane)
planeNode.position = SCNVector3(textWidth/2,1.5*textHeight,-0.0001)
textNode.addChildNode(planeNode)

"由于执行过程中的错误,命令缓冲区的执行被中止。已忽略(因为导致先前/过多的GPU错误)">

当我的文本过于复杂时,我遇到了这个问题。我通过增加SCNTextflatness来减少多边形的总数,并且能够渲染更多的文本。

text.flatness = 0.6    // default value
text.flatness = 0.0005 // more polygons, higher complexity
text.flatness = 1.0   // lower polyon, lower complexity (uglier text)

尝试降低复杂性。照明、多边形总数、材料复杂性等

相关内容

最新更新