Try running it in a debugger so you can get a stack trace when it crashes. Then, you can look at where it crashed, and what your variables were set to. This sort of problem is often due to improperly initialized variables, or buffer overruns.