miho / JCSG

Java implementation of BSP based CSG (Constructive Solid Geometry)
Other
177 stars 52 forks source link

Multiple uinions cause StackOverflow Error #59

Open Fliens opened 4 years ago

Fliens commented 4 years ago

I've written this code:

public class Main {

    public static void main(String[] args) throws IOException {
        CSG cube = STL.file(Paths.get("cube.stl"));

        CSG union = cube;
        for (int x = 0; x < 100; x++) {
            union = union.union(cube.transformed(Transform.unity().translateX(x * 10)));
        }

        try {
            FileUtil.write(Paths.get("sample.stl"), union.toStlString());
        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

But after 26 unions i get this error:

Exception in thread "main" java.lang.StackOverflowError
at java.util.stream.AbstractPipeline.wrapSink(Unknown Source)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)
at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.util.stream.ReferencePipeline.collect(Unknown Source)
at eu.mihosoft.jcsg.Node.build(Node.java:244)
at eu.mihosoft.jcsg.Node.build(Node.java:265)

I'm trying to combine multiple objects to one but unluckily i get this error :/

skanga commented 3 years ago

Try increasing the size of your stack on the Java command line by using something bigger like -Xss1024m

madhephaestus commented 3 years ago

This may be related to #54 and has PR #64 to address it.