Page 1 of 1

WTF?!? stupid error out of the blue. help pls!

Posted: Tue Jul 26, 2005 9:42 am
by Rabid Mantis
for no apparent reason whatsoever, whenever I try to run my program I get this error

An unhandled exception of type 'System.StackOverflowException' occurred

...and it always points to where I declare my event handler. MyEventReceiver receiver;

Now, in an attempt to figure out wtf is going on, I eliminated my code section by section and found out that this code is causing the problem.



CHARACTER Random_Character()
{

CHARACTER rcharacter;
return(rcharacter);

} // End Random_Character


CHARACTER is a structure of a bunch of different variables, nothing fancy. I get the error if I call this in any way. I tried the simplest way I can think of:

CHARACTER lcharacter = Random_Character();


but I get the overflow error when I call it. Any idea what the problem could be? I've tried rebooting my computer and cleaning the solution etc. also, I made no changes to this code whatsoever before the problem came up.

help pls, I'm stumped :(

Posted: Tue Jul 26, 2005 10:46 am
by DexteR
A NULL value was return when I receive StackOverFlow error
base on my expereince.

Try to initialize entities in your character class.


e.g.


YourClass::Character
{
int Var1,
int Var2
}
: Var1 ( 0 ), // <<< Initialization
Var2 ( 0 ) // <<< Initialization
{
.
.
.
// your routine
.
.

}

Posted: Tue Jul 26, 2005 12:01 pm
by Spintz
And so you know, structs are just like classes, in that you can declare ctors and dtors for structs as well.

Posted: Tue Jul 26, 2005 12:39 pm
by Rabid Mantis
So I should make sure to enter a value in for all my variables in the structure? I didnt know that could cause a problem if I didnt. I'll try that.

Posted: Tue Jul 26, 2005 4:23 pm
by Spintz
Another point to node, in Debug mode, at least with Visual Studio, when it runs, it will automatically initializae values for you, like floats to 0.0, and integers to 0, pointers to NULL, etc.

However, in Release mode, if it's not initialized to a value, it's initial value is undefined. So pointers could point to invalid data ( and not 0 ), integers are basically the value of the 4bytes their memory points to, whatever happened to be left in memory, etc.

So, you may not notice so many problems in Debug mode, but you may get crashes and unexpected behavior if you run in Release mode.

Posted: Wed Jul 27, 2005 8:21 pm
by Rabid Mantis
I tried entering 0 for every last value in CHARACTER before returning it, and made sure my compiler was set on debug, and it still doesnt work. I'm not sure exactly what syntax to use to initialize my structures. can someone show me how on this small example structure?


typedef struct HQ
{

wchar_t name[500];
s32 location;
s32 population;
s32 race;

} HQ, *HQ_PTR;



putting (0) or =0 after a variable just gives me an error.
I also made sure that the error occurs whenever I actually return it.

Posted: Wed Jul 27, 2005 11:36 pm
by Acki
Do the initialisation in the class's constructor...