Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Unhandled Exception Stack Overflow in crtexe.c  (Read 3967 times)

0 Members and 1 Guest are viewing this topic.

ScorpionWasp

  • Newbie
  • *
  • Posts: 6
    • View Profile
Unhandled Exception Stack Overflow in crtexe.c
« on: October 22, 2015, 12:50:09 am »
I'm using Visual Studio Express 2013 with SFML 2.3.2.
I have this class called World and I create a pointer to it in main. I then create a new World with the pointer:

World *W = new World;

No problems up to this point. Then I thought to myself, "Why am I creating a pointer to a class I'll have only one unchanging instance of throughout the entire execution? Having to look an object's address up as if it can change when it never does is wasteful, right? So I changed it to static allocation instead:

World W;

All hell broke loose. The moment execution enters void main at all, before getting to the first line of code inside, I get an unhandled exception, stack overflow in crtexe.c. Any ideas?

Arcade

  • Full Member
  • ***
  • Posts: 230
    • View Profile
Re: Unhandled Exception Stack Overflow in crtexe.c
« Reply #1 on: October 22, 2015, 07:20:07 am »
Unfortunately no one will be able to give you an exact answer without seeing your code.  Without the code the best we can do is take guesses. Before posting it, though, please strip out anything not needed to reproduce the problem so that it is as minimal as possible. That way we can try compiling and running it ourselves to see where the problem is.

Having said that, here is my guess. Does your World class have very large member variables? Perhaps a very big array or something like that? A stack overflow is usually what it sounds like, your object is too big to live on the stack. Dynamically allocated memory (using new) gets put on the heap and avoids that problem. If your world class really is too big for the stack then perhaps you can redesign it to be smaller.

ScorpionWasp

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Unhandled Exception Stack Overflow in crtexe.c
« Reply #2 on: October 22, 2015, 06:56:22 pm »
Bingo! World holds information on the entire 1000x1000 tile map after all. As soon as I commented that part out, it started accepting both implementations. Funny thing is, the stack overflow happens before the first line of code inside main is executed at all, before it even gets to "World W;".

Yeah, I'm quite the noob at this stuff. So... is there any way to keep this class large as it's supposed to be, but at the same time tell the compiler "don't query this object's address every time you access it, the address is always the same!"?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10821
    • View Profile
    • development blog
    • Email
Unhandled Exception Stack Overflow in crtexe.c
« Reply #3 on: October 22, 2015, 07:21:26 pm »
Let the tilemap be allocated on the heap at best through a vector instead of arrays.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Unhandled Exception Stack Overflow in crtexe.c
« Reply #4 on: October 22, 2015, 10:45:16 pm »
Funny thing is, the stack overflow happens before the first line of code inside main is executed at all, before it even gets to "World W;".
I'm guessing that's with an optimized build. The optimizer can often lead to "weird" things like that. Try a unoptimized debug build for more "human readable" results.

ratzlaff

  • Newbie
  • *
  • Posts: 33
    • View Profile
Re: Unhandled Exception Stack Overflow in crtexe.c
« Reply #5 on: October 23, 2015, 01:59:12 am »
The visual studio compiler sets the stack frames at a 1-megabyte limit, sounds like you have gone over that.

To change this, either do what has already been suggested in re-organizing your data structures, or change the setting in your project's properties -> Linker -> System -> Stack Reserve Size

 

anything