Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call Stack problems #23

Open
Yenza opened this issue Jan 25, 2016 · 10 comments
Open

Call Stack problems #23

Yenza opened this issue Jan 25, 2016 · 10 comments

Comments

@Yenza
Copy link

Yenza commented Jan 25, 2016

Using three.min.js rev 73

Method used:
var roomBSP = new ThreeBSP(_RoomShape); // HUGE SHAPE

Info gathered from a TryCatch:
"number : -2146828260"
"Error: Out of stack space
at ThreeBSP.Vertex.prototype.dot (/ThreeCSG.js)
at ThreeBSP.Polygon.prototype.classifyVertex (
/ThreeCSG.js)
at ThreeBSP.Polygon.prototype.classifySide (/ThreeCSG.js)
at ThreeBSP.Polygon.prototype.splitPolygon (
/ThreeCSG.js)
at ThreeBSP.Node (/ThreeCSG.js)
at ThreeBSP.Node (
/ThreeCSG.js)
at ThreeBSP.Node (/ThreeCSG.js)
at ThreeBSP.Node (
/ThreeCSG.js)
at ThreeBSP.Node (/ThreeCSG.js)
at ThreeBSP.Node (
/ThreeCSG.js)"

Using the OUTDATED csg-wrapper from kraag22/csg-wrapper it doesn't happen but his wrapper is way outdated and needs an update.

Might this occur when using high values/numbers?

Another example:
var intersect = shape1.intersect(shape2); // Small shapes

Info gathered from a TryCatch:
"number : -2146828260"
-:-

@Wilt
Copy link
Contributor

Wilt commented Jan 27, 2016

I have an updated fork here

@Yenza
Copy link
Author

Yenza commented Jan 27, 2016

Your fork is exactly the same except missing the face.vertexNormal fix

@Wilt
Copy link
Contributor

Wilt commented Jan 27, 2016

Owh, sorry. I thought that there were more fixes in my fork...

@Wilt
Copy link
Contributor

Wilt commented Jan 27, 2016

I provided the vertex normal fix...
But I accidently pointed to the master, and that fix was in this patch1 branch.

@Yenza
Copy link
Author

Yenza commented Jan 27, 2016

Your branch is fully up-to-date with Chandlers and you both provide exact same ThreeCSG.js files.
I've just compared with a SVN program. No changes.

@Wilt
Copy link
Contributor

Wilt commented Jan 27, 2016

@Yenza Yes, you are right. He recently merged my patch1...

@chandlerprall
Copy link
Owner

Maximum call stack happens with complex geometry for two reasons:

  1. ThreeCSG doesn't use any heuristic for picking a good divider
  2. Even if a great divider is selected it is still possible to reach maximum recursion. The proper fix would be to change the recursion into one function that keeps a local stack queue and while() loops over it.

Solving either of these would gain large speed improvements, especially for complex geometries. There are many white papers / thesis on CSG which provide ideas for selecting a good divider. Unfortunately I won't have time for a while to actively look into implementing.

@Yenza
Copy link
Author

Yenza commented Jan 28, 2016

@Wilt Do you think you could try to fix this issue?

@chandlerprall But it isn't that very complex! It's two round shapes! It's two identical "almost" circle-wise shapes on the same height. The thing is that if I move any of them like 1 unit in any direction.. then it works! I have an image of the red area when using the intersect method that causes an error:
http://i.imgur.com/NW0AOUU.png

Also this problem doesn't seem to be occurring when you use the old csg wrapper but that might just be because it's heavily outdated.

@Yenza
Copy link
Author

Yenza commented Jan 28, 2016

So this is what I did to fix this for now... I dunno why it works but it does. The "var test = new ThreeBSP(shape)" doesn't though x.x

var intersection;
try {
    // If it doesn't work the first time...
    intersection= shapeBSP.intersect(shapeBSP_2);
}
catch (e) {
    // Then try again..
    var newShape = shapeBSP_2.toMesh(_Material);
    newShape.position.x += 1;
    newShape = new ThreeBSP(newShape );
    intersection= shapeBSP.intersect(newShape);
    // console.warn("Works!");
}

@jgphilpott
Copy link

FYI this new CSG repo using Octree data structure overcomes a lot of the performance issues with ThreeCSG and other CSG tools. See this SO thread for up to date information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants