I'm building a binary tree based on the xml document I'm parsing with TinyXML2,(Is 3 the right name now?) so dialogue branches from documentation go into the engine correctly. I had an implementation of the initial tree that was almost working, but Nodes in the XML doc aren't sorted in the order they go in, and the Id for each value isn't in numerical order. A few of the dialogues ended up in the tree correctly, but it didn't work for every dialogue in the XML. Thus, I'm currently experimenting by looping through the document and dropping nodes in the order they should go for each dialogue. The only problem is after looping through a few times TinyXML causes a segfault.
The doc has two basic sections. Psuedocode for it is below.
<Content>
<DialogueFragment Id="10">
//..
<DialogueFragment/>
//...
</Content>
<Hierarchy>
<Node Type="Dialogue" Id= "1">
<Node Type="DialogueFragment" Id="10"/>
<Node Type="Connection" Id="2"/>
</Node>
</Hierarchy>
I'm starting with the top Dialogue with Id 1, and figuring out which DialogueFragment comes first, based on the Connection having Dialogue Id as the source and DialogueFragment Id 10 as the target. Then repeating that process for DialogueFragment Id 10 as the connection source, and so on till no more children are left. I tried just searching through the Hierarchy from top to bottom, for each Dialogue, but the only problem is when the documentation software generates XML the nodes aren't always listed in the correct order, and their numerical value doesn't indicate the order they go in.
My code is pretty messy right now, since I'm trying to figure out the correct algorithm for sorting nodes in the correct order, before adding them to my tree structure. Anyone know how to prevent the segfault caused by TinyXML2 when using FirstChildElement?