RE: Custom error message for stack overflow in C++
August 10, 2021 at 4:11 pm
(This post was last modified: August 10, 2021 at 4:55 pm by HappySkeptic.)
I've looked at your code, and you are making heavy use of the stack. The default stack size is 1 MB on Visual Studio, but you can change that with a compiler flag.
It is possible you have simply run out of stack.
Experienced programmers learn to use very little stack space, and use the heap instead. That requires making use of things like shared_ptr<> rather than copying large objects into new variables (it also helps with performance).
I notice that every TreeNode generates some data which looks like it is the same for all instances. That is wasteful - it should be static and initialized statically. That also causes much less data to be copied.
If you increase the stack, still get the error, and get an even deeper stacktrace on the same lines of code, then you know you have an infinite loop. Just walk the stacktrace and look at the lines and data, and fix it. You think you don't have an infinite loop (something I haven't verified), so just use the larger stack. But, you really shouldn't be using so much stack space.
Set Stack Size
I don't know how to change the compile parameters directly from CMake, but it is easy to temporarily make a change in the generated VS project file.
It is possible you have simply run out of stack.
Experienced programmers learn to use very little stack space, and use the heap instead. That requires making use of things like shared_ptr<> rather than copying large objects into new variables (it also helps with performance).
I notice that every TreeNode generates some data which looks like it is the same for all instances. That is wasteful - it should be static and initialized statically. That also causes much less data to be copied.
If you increase the stack, still get the error, and get an even deeper stacktrace on the same lines of code, then you know you have an infinite loop. Just walk the stacktrace and look at the lines and data, and fix it. You think you don't have an infinite loop (something I haven't verified), so just use the larger stack. But, you really shouldn't be using so much stack space.
Set Stack Size
I don't know how to change the compile parameters directly from CMake, but it is easy to temporarily make a change in the generated VS project file.