Haywire Node Positioning

I am in a HUGE jam!
I have just about every aspect of my family tree working perfectly. However, I am experiencing a VERY unusual phenomenon.
I started off my development using the family tree as an example. I have modified it considerably over the last few weeks but the basic functionality provided in the sample code that generates the tree has more or less stayed the same. The way the links are created (i.e. child and marriage) and the way nodes are stored in the dictionary hashtable etc. are all pretty much the same.
Since a married couple are related to one another by their children, you cannot just add a spouse to an existing node. You must add a “Mate and son/daughter”. Doing so creates 2 new nodes and stores the fatherid and motherid in the newly created child record to be used when regenerating the tree.
A blank family tree always starts off with a single node. Adding parents to that node works fine. No quirks.
Adding a sibling to that node also works fine.
The trouble starts when I try to add a spouse and child to an existing node.
The frustrating part is that it only happens SOME of the time. The outcome is like totally random.
To prove my point I just went and started adding spouses and children willy-nilly to just about every node that wasn’t already married. I had expected the crazy node positioning to happen pretty much after the first new nodes were created and for certain after I created some more. Sure enough everything seemed to be positioned fine. All of the locations of the existing nodes were recalculated based on the new additions to the tree and everything looked normal. Then I added parents to the father of the highest parent and everything went crazy. The new child keeps defaulting to the top left corner of the document.

Any thoughts?

FamilyTree.FamilyTreeDoc.LayoutNodes() isn’t very smart, so I could easily imagine that it’s doing something wrong. It works by first moving each node to the origin, so that might account for the behavior that you see. I don’t know why the next step, of calling FamilyTreeDoc.LayoutTree, doesn’t work in those cases that you see. You’ll need to debug that code.