Most common cause is indeed stack overflow.
The quick & dirty way to find stack errors is to download the code through the debugger, then in the memory map, set every byte in the whole stack area to a certain value, like 0xAA.
After that, start the program and let it run. When it catches the breakpoint for illegal instruction, pick up the memory map and check the stack. You should be able to see how much of the 0xAA on the stack that the program has munched away at. If it is all the way to the top, or close, then the cause is stack overflow.