Search code examples
iosswiftrenderingmetalpolyline

iOS Metal poly-line diverges to some distant point. How to find the offending position?


I'm using Metal to render a line strip of a million points, and it works. However, I see that random line segments diverge to some arbitrary point (see screenshot).

How do I find the points that break line strip rendering and exclude them from rendering?

let particle = slice.rowParticleBuffer[pointIndex]

if particle.position.x.isNaN || particle.position.y.isNaN || particle.position.z.isNaN {
    print("x", terminator: "") //does not hit this
} else if fabsf(particle.position.x) > 10 || fabsf(particle.position.y) > 10 || fabsf(particle.position.z) > 10 {
    print("Z", terminator: "") //does not hit this either
} else {
    self.particlesBuffer[self.index] = slice.rowParticleBuffer[pointIndex]
    self.index += 1
}

enter image description here

enter image description here


Solution

  • So the magical point turned out to be zero, caused by an indexing error (code was skipping over some indices, leaving the master buffer having a zero value).

    let particle = slice.rowParticleBuffer[pointIndex]

      if particle.position.x == 0 || particle.position.y == 0 || particle.position.z == 0 { /*skip*/ }