Basically, the backtrace is trace of the calls that lead to the crash. In this case:
game::play
called game::make_computer_move
which called Checkers::make_move
which called Space::setPosition
which crashed in line 44 in file space.h
.
Taking a look at this backtrace, it looks like you passed -65
and -49
to Space::setPosition
, which if they happen to be invalid coordinates (sure look suspicious to me being negative and all). Then you should look in the calling functions to see why they have the values that they do and correct them.
I would suggest using assert
liberally in the code to enforce contracts, pretty much any time you can say "this parameter or variable should only have values which meet certain criteria", then you should assert that it is the case.
A common example is if I have a function which takes a pointer (or more likely smart pointer) which is not allowed to be NULL
. I'll have the first line of the function assert(p);
. If a NULL
pointer is ever passed, I know right away and can investigate.
Finally, run the application in gdb, when it crashes. Type up
to inspect the calling stack frame and see what the variables looked like: (you can usually write things like print x
in the console). likewise, down
will move down the call stack if you need to as well.
As for SEGFAULT
, I would recommend runnning the application in valgrind. If you compile with debugging information -g
, then it often can tell you the line of code that is causing the error (and can even catch errors that for unfortunate reasons don't crash right away).