Our server costs ~$56 per month to run. Please consider donating or becoming a Patron to help keep the site running. Help us gain new members by following us on Twitter and liking our page on Facebook!
Current time: July 30, 2025, 10:51 pm

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Custom error message for stack overflow in C++
#11
RE: Custom error message for stack overflow in C++
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.
Reply



Messages In This Thread
RE: Custom error message for stack overflow in C++ - by HappySkeptic - August 10, 2021 at 4:11 pm

Possibly Related Threads...
Thread Author Replies Views Last Post
  What is the most absurd error message a program you have made was outputting? FlatAssembler 38 8569 June 14, 2023 at 8:01 am
Last Post: FlatAssembler
  Error 502 bad gateway for Rational Responders Brian37 13 2423 April 23, 2022 at 4:17 pm
Last Post: BrianSoddingBoru4
  How Do I Send an SMS message From UK mobile to a US one ReptilianPeon 11 2696 July 9, 2018 at 5:17 pm
Last Post: bennyboy
  HELPPPPP Blue screen error just now!!! Edwardo Piet 114 16066 November 10, 2015 at 2:26 am
Last Post: Aractus
  Disk read error. Creed of Heresy 12 4729 July 27, 2012 at 9:19 am
Last Post: Tiberius
  Video Error: Grey circle with a white exclaimation mark inside. Reforged 5 4355 July 5, 2012 at 1:19 am
Last Post: Reforged



Users browsing this thread: 1 Guest(s)