Sign in to follow this  

weird bug: Stack Overflow

This topic is 4714 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I get this error: First-chance exception in Shell.exe: 0xC00000FD: Stack Overflow. I've never seen that before. What does it mean? If I run the debugger it exits at a line of code I know isn't wrong so its elsewhere in my code and I know where, but don't know what the error message means so its hard to fix without knowing the real problem...arg thanks!

Share this post


Link to post
Share on other sites
Quote:
Original post by slayemin
I get this error:
First-chance exception in Shell.exe: 0xC00000FD: Stack Overflow.

I've never seen that before. What does it mean?
If I run the debugger it exits at a line of code I know isn't wrong so its elsewhere in my code and I know where, but don't know what the error message means so its hard to fix without knowing the real problem...arg
thanks!


Can we see the code that it exits on please? I know you have said that you know it is not wrong - but you know how stuff happens. Basically a stack overflow means a few things - an endless loop most of the time that performs some operation too many times *I belive*. Maybe some memory allocations on the stack or the heap - or maybe an array out of bounds access. I'm not that sure - I would have to see code before I could offer more specific suggestions.

Here is a link on stack overflow

- Drew

Share this post


Link to post
Share on other sites
This is the exit point, which is inlined in a class

class PEICE
private:
int Type;
public:
int GetType(){return(Type);} //when we need to poll the peice type




And here is what I believe is the real source of the problem:

bool Is_In_Check(int Color)
{
/*
PURPOSE:
Test to see if the king is in check.
INPUT:
Color - The color we are checking for "in check" status
OUTPUT:
true -The king is in check
false -king is not in check
Theory:
Go thru every enemy peice on the board and test to see if it can move onto the kings tile

or just have a function that checks how many enemies can move to a grid on their next turn.
Can also check if a castle attempt is valid. simply test some extra tiles between king and rooks
*/

PEICE *KingPeice = TopPeice;
POINT KingLocation;

while(KingPeice!=NULL)
{
//if the peice is a king
if(KingPeice->GetType()==KING)///<<<<<<<<<<<THIS LINE HERE<<<<<<
{
//if the color of the king matches the input
if(KingPeice->GetColor()==Color)
{
KingLocation = KingPeice->GetLocation();
break;
}
}
KingPeice = KingPeice->Next;
}

//go through every enemy peice and see if it can attack the king
PEICE *EnemyPeice = TopPeice;
while(EnemyPeice!=NULL)
{
//filter out all friendly peices
if(EnemyPeice->GetColor()!=Color)
{
//if the enemy peice can possibly move to the kings location
if(Get_Possible_Move(EnemyPeice,KingLocation))
{
return(true);
}
}
EnemyPeice = EnemyPeice->Next;
}
/**/

return(false);
}

Share this post


Link to post
Share on other sites
Only thing I see wrong with that code (other than you spelled PIECE wrong) is no opening brace "{" after class declaration. Another reason you may get a stack overflow (in addition to what Drew listed) is infinite recursion or even non infinite recursion that clogs up the stack. I don't see any recursion at all or any flaws in your logic...

Share this post


Link to post
Share on other sites
That code is not enough code to see any recursion.

Anyway, I don't think you need to post code. What you need to do is learn how to make use of the debugger to look at the call stack. Once you can find the call-stack viewer and use it, it will then be clear what the problem is. Look at the last few levels on the stack and you should see some kind of repetition. Stack overflow problems are easy to diagnose when you know how.
If you are using MSVC++ then you should be able to find the call-stack window in a menu or something somewhere.

Also beware to not have many big local arrays as that can also cause this.

Share this post


Link to post
Share on other sites
OOOOOooooooooh, I got it. Here, I'll share how it was getting the stack over-flow, which is indeed what was happening, but in a sneaky way:

1. use the code above to see if the king is in check "Is_In_Check()"
2. Go through every enemy peice to see if it can move to the king
3. inside the enemy peice code, see if moving the peice would put the king in check by calling the "Is_In_Check()" function (which is the recusive part)

the code was all correct syntactically, it just...filled the stack infinitely :)
thanks for the help and the link.

:P Rats. Now to think of another way to solve this problem...

Share this post


Link to post
Share on other sites
OMG!!! WOW!!! That is cool! Call Stack!! I've been trying to figure something like that out by writing a debug file which has all the info the call stack provides. wow. this is really cool! major thanks iMalc!!

Share this post


Link to post
Share on other sites

This topic is 4714 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this