Have you tried running your program thru your debugger. The debugger should be able to tell you exactly where it detects the error. And you can view the values of your variables at the time of the crash.
Also could you fix your code posting, repost without the line numbers.