nicklockwood/ShapeScript

Crash in Mesh.subtract

mgrider opened this issue · 3 comments

Here's what I'm trying to do: Use Euclid in a ARKit app.

Here's what I did:

  1. Create a new “Augmented Reality” project in Xcode. (12.5.)
    1. You’ll need to select SceneKit in the “Content Technology” dropdown.
  2. Add the Euclid as a Swift Package Manager dependency.
    1. Go to: File > Swift Packages > Add Package Dependency
    2. Add https://github.com/nicklockwood/ShapeScript.git
  3. Open ViewController.swift
    1. add import Euclid at the top of the file.
    2. Comment out (or delete) the line of code that creates a new scene from ship.scn
    3. Added the following lines in its place (these are from the EuclidExample project):
	// Create a new scene
        let scene = SCNScene()

        // create and add a camera to the scene
        let cameraNode = SCNNode()
        cameraNode.camera = SCNCamera()
        scene.rootNode.addChildNode(cameraNode)

        // place the camera
        cameraNode.position = SCNVector3(x: 0, y: 0, z: 3)

        // create some geometry using Euclid
        let start = CFAbsoluteTimeGetCurrent()
        let cube = Mesh.cube(size: 0.8, material: UIColor.red)
        let sphere = Mesh.sphere(slices: 120, material: UIColor.blue)
        let mesh = cube.subtract(sphere)
        print("Time:", CFAbsoluteTimeGetCurrent() - start)
        print("Polys:", mesh.polygons.count)

        // create SCNNode
        let geometry = SCNGeometry(mesh)
        let node = SCNNode(geometry: geometry)
        scene.rootNode.addChildNode(node)
  1. Provisioning bs...
  2. Build and run on my device. (iPhone 12 Pro Max)

I get this crash:

Screen Shot 2021-06-17 at 11 51 33 AM

The app does build and run in the iPhone 12 Pro Max simulator, with the following in the logs:

2021-06-17 11:53:03.035867-0500 EuclidSKAR[9123:636030] Metal GPU Frame Capture Enabled
2021-06-17 11:53:03.036055-0500 EuclidSKAR[9123:636030] Metal API Validation Enabled
Time: 12.664151072502136
Polys: 3574
2021-06-17 11:53:16.680852-0500 EuclidSKAR[9123:639525] fopen failed for data file: errno = 2 (No such file or directory)
2021-06-17 11:53:16.680957-0500 EuclidSKAR[9123:639525] Errors found! Invalidating cache...
2021-06-17 11:53:16.943133-0500 EuclidSKAR[9123:639525] fopen failed for data file: errno = 2 (No such file or directory)
2021-06-17 11:53:16.943270-0500 EuclidSKAR[9123:639525] Errors found! Invalidating cache...

Interestingly observations:

  1. The example project does build and run on my phone.
  2. I get the same error even if I add all the code above in a background thread.

I just realized that probably this issue would be more relevant over on the Euclid repo than here. Sorry about that. Want me to move it over there?

I removed the ShapeScript dependency entirely, and re-added Euclid, and now I do get the error in the simulator. I'll re-make this issue on the Euclid repo. Sorry for the confusion.

@mgrider yes please :-)