I am getting a strange crash while testing a geometry class I wrote. When I add a child to my class the Windows error message sound is heard, but no messagebox pops up. I figure that I'm doing something funky with my pointers but not really too sure, and skipping through the debugger is no help either. After g.SetParent is called, g has the correct values, so I have no clue what's going on.
Basically, I am using my class like this:
Geometry gr; // geometry root
Geometry ch1; // child 1
Geometry ch2; // child 2
Geometry ch1_1; // child 1's child 1
Geometry gr_1; // geometry root's child 1
gr.AddChild(ch1); // Crashes here but debugger doesn't stop on anything, even inside the function
gr.AddChild(ch2);
ch1.AddChild(ch1_1);
ch1_1.GetParent()->GetParent()->AddChild(gr_1);
And the relevant parts of the class:
void Geometry::SetParent(Geometry *g)
{
m_pGeoParent = g;
}
Geometry *Geometry::GetParent()
{
return m_pGeoParent;
}
void Geometry::AddChild(Geometry g)
{
m_vGeoChildren.insert(m_vGeoChildren.end(), g);
g.SetParent(this);
m_bHasChildren = true;
} // stepping through the debugger skips right over the closing brace and the Windows error sound is heard
The members that keep track of parent/children are defined like this:
Geometry *m_pGeoParent;
std::vector<Geometry> m_vGeoChildren;
Anyone have any idea what's going wrong?