This is definitely very weird. I'm using OpenSceneGraph, and I'm trying to add a node as a child of another node using their osg::Node::addChild() method. The osg::Node has a list of parents and a list of children, each implemented as a std::vector<osg::Node*>.
So, when I add a child to a parent, the parent first adds the child to its list of children, and then it calls on the child's addParent() method. Pretty straight-forward.
For some reason, with one of the nodes, the vector throws an exception in debug mode during the addParent() step. The stack trace looks like this (edit - it was way too long, horizontally, so I edited out the parameter lists and line numbers from the following stack trace to make it easier to read):
msvcp90d.dll!std::_Container_base_secure::_Orphan_all()
osg55-osgd.dll!std::vector<>::_Insert_n()
osg55-osgd.dll!std::vector<>::insert()
osg55-osgd.dll!std::vector<>::push_back()
osg55-osgd.dll!osg::Node::addParent()
osg55-osgd.dll!osg::Group::insertChild()
And I stepped through it, and what's happening is, it seems to want to reallocate the internal buffer, probably because this is the first time adding anything to the vector, and (I'm guessing) the vector's initial capacity is zero.
And then it needs to invalidate all the iterators (what iterators? the begin and end iterators, maybe? I'm not sure). So, it calls _Orphan_all().
Once it gets into _Orphan_all(), it simply uses a for-loop to cycle through the iterators. It looks like this:
for (_Iterator_base **_Pnext = (_Iterator_base **)&_Myfirstiter; *_Pnext != 0; *_Pnext = (*_Pnext)->_Mynextiter)
(*_Pnext)->_Mycont = 0;
So, each cycle of the loop, it just sets _Mycont to 0, and then steps to the next iterator using the expression *_Pnext = (*_Pnext)->_Mynextiter.
The problem is, the loop breaks when the *_Pnext != 0 test fails, right? Well, there's an iterator in this list with an unitialized Mynextiter. So, if I step through this loop for a few cycles, eventually the value of (*_Pnext) becomes 0xcdcdcdcd, and kaboom.
I can definitely see why that'd be a problem. Does anyone have any guesses as to why this is happening?