When your program is getting a serious error during execution the problem
might not be obvious. Here are some suggestions.
This will sound like a lot of work but this is more than just words, I
have done what I suggest myself.
Reduce your program down to the most minimal program possible that
recreates the problem. Try to make it as small as possible. When the problem
goes away, undo what you just did then try to remove other parts until you
get to the smallest as possible. Then if the problem has not been
identified, analyze what you have as much as you can. Then if you can't
figure it out then hopefully the sample will be small enough that you can
post the entire source that recreates the problem in a forum.
I once spent a few hours doing that and then someone else was able to see
very quickly that I had done something stupid. Don't feel bad if you finally
realize that the problem is very obvious once it becomes obvious.
Consistent with that, problems are often so simple that we can't see them
because we are expecting something difficult.