Check your boundaries- not just arrays (i know :P :P)... This sounds really obvious due to the Error you're getting- But youre managing to try to write/read memory you shouldnt/havent said you were going to.
Tis the only thing i can think of.
Tis the only thing i can think of.