Enabled range checking, overflow checking etc. and generate a stack backtrace. That should give an idea as to where the bug is.