corrupted stack pointer
I have a thread A in my code. Even though the stack is not full, I sometimes see that I have an invalid value of the stack pointer (the stack pointer value is outside the stack size range for that thread) and see a stack overflow error. Any tips on what are the possible ways this could happen? and how I could possibly debug this?
The typical way for such a thing to happen is to go walking off the end of an array.
But that doesn't usually cause the stack pointer to point somewhere weird.
Originally Posted by tabstop
Normally, the only way the stack pointer could become invalid is if you entered an infinite recursion, or tried to allocate too big of an object on the stack.
Given that it crashes, I assume he's not just seeing the stack pointer from some other thread (it's easy to confuse yourself with the debugger) and in fact there is something wrong. I'd start by examining any recursive functions or functions which allocate large stack variables.
EDIT: If this is on Windows, there is a strange thing involving floating point that can result in a "stack overflow" (it's not, it's Windows messing up) but we'll get there when we get there...
One way in VS is to add a breakpoint to any loops of suspected infinitely recursive functions, that breaks at or after a certain number of hits.
But then, you haven't told us what environment you're using yet :(