Closed mgrider closed 3 years ago
@mgrider hi, just to let you know I was able to recreate the crash (only on device, not on the simulator). I've no idea yet what's causing it.
@mgrider reducing the number of slices down from 120 to 110 fixes the problem, so I strongly suspect it's a stack overflow.
@mgrider CSG operations are highly recursive, so they can cause the stack to overflow if you have very complex meshes. You can solve this one of two ways, either reduce the mesh complexity, or increase the stack size.
You can increase the stack size by creating a new Thread
and then setting the desired size, as follows:
// Create a new scene
let scene = SCNScene()
let thread = Thread {
// 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
DispatchQueue.main.async {
let geometry = SCNGeometry(mesh)
let node = SCNNode(geometry: geometry)
scene.rootNode.addChildNode(node)
}
}
thread.stackSize = 4 * 1024 * 1024 * 1024 // set stack to 4GB
thread.start()
@mgrider I've pushed a new version of Euclid (0.4.5) that changes the CSG implementation so these stack overflows won't occur. That means you'll no longer need to increase the thread stack size.
That's awesome, thank you so much! This project is fantastic, btw. I don't really think I'm going to have time to build it, but my idea was an AR enabled 3D modeling program so you can position the geometry over the thing you are trying to model. Just adding and subtracting primitives would be pretty huge, I think. Another cool use case would be to clean up meshes created by 3D scanning with Lidar enabled devices.
@mgrider sounds like a cool idea, hopefully you get a chance to work on it 👍
Here's what I'm trying to do: Use Euclid in a ARKit app.
Here's what I did:
SceneKit
in the “Content Technology” dropdown.File > Swift Packages > Add Package Dependency
https://github.com/nicklockwood/ShapeScript.git
Open
ViewController.swift
import Euclid
at the top of the file.ship.scn
Added the following lines in its place (these are from the EuclidExample project):
I get this crash:
Interestingly observations: