It's not obvious what the actual problem is. If you could provide a
simplified version of your program that demonstrates the failure, that
would be a big help.
Here's a systematic process for simplifying your code:
1. Start with a program that is known to demonstrate the problem you've
run into. Create two copies of your program, the saved copy and the
working copy.
2. From the working copy, choose something to remove. It should be as
big as possible, and something that seems unlikely to be relevant to the
problem you're running into. A good starting point would be to remove
everything that's supposed to happen after the point where a problem
occurred. Each time you reach this step, remember to remove a different
something.
3. Remove that part, and test to see if you still see the problem.
4a. If you do see the problem, remove the saved copy, replacing it with
the working copy.
4b. If you don't see the problem, think long and hard about that fact.
You removed something that wasn't supposed to effect the problem - but
it did. That's a clue about something you didn't understand. Oftentimes,
while following this procedure, you will figure out the problem yourself
by careful consideration of those clues.
If you haven't resolved the problem, delete the working copy.
5. Go back to step 2.
This process ends when you figure out the problem, or when you have no
new ideas as to what to remove.
In that later case, you've got something suitable for presentation to
this newsgroup. Remember, when posting it, to include the following
information:
1. The full text of the program, cut-and-pasted from the actual sources.
Don't type it in - you don't want us to waste our time investigating
your typos.
2. Precisely how you built the code: what platform, what compiler, which
command line options, etc.
3. What you expected to see. Keep in mind that if your expectations are
wrong, it will be hard for people to realize that if you don't tell them
what your expectations are.
4. Cut-and-paste of the text that demonstrates that something other than
what you expected, happened. That might include error messages, a dump
of the output file, or any of several other things. Don't just say "it
didn't work".