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

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Rabid Mantis
Posts: 61
Joined: Sun May 08, 2005 11:30 am

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

Post 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 :(
DexteR
Posts: 15
Joined: Mon Jul 18, 2005 1:52 am
Location: @ Kernel32.DLL

Post 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
.
.

}
AnimaKomix: A Half-3D Packer & Animator
http://www.freewebs.com/project_z/
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

And so you know, structs are just like classes, in that you can declare ctors and dtors for structs as well.
Image
Rabid Mantis
Posts: 61
Joined: Sun May 08, 2005 11:30 am

Post 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.
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post 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.
Image
Rabid Mantis
Posts: 61
Joined: Sun May 08, 2005 11:30 am

Post 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.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Do the initialisation in the class's constructor...
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Post Reply