I am trying to limit myself here, instead posting a wall of codes.. |
Always appreciated. Distilling the code to the smallest example that exhibits the problem you're experiencing is usually recommended.
But let me revisit what I said before:
I suspect, since you seem to be copying nodes instead of keeping them in once place, that your pointers are invalidated at some point. |
On line 1 of your second code snippet above, you copy a variable in a container to the variable
parent. On line 8 you set the
parent pointer of a node to the address of the
parent object manipulated earlier.
Now, if the function this code occurs in terminates, the
parent variable is destroyed and the
parent pointer of the node in your container will point to an invalid object. If this is part of a loop and
parent is reassigned a value on another iteration of the loop, the
parent pointer of the node in your container will point to a node that is not it's parent.
This is the sort of context I'm talking about.