[osg-users] Error: 'Debug Assertion Failure!'

Sullivan, Joseph (CDR) jasullivan at nps.edu
Thu Jan 3 08:52:23 PST 2008


This might be helpful under the general topic of loop structures for deleting elements from STL containers while avoiding invalidating iterators...
http://blog.codedread.com/archives/2007/11/30/c-stl-safely-removing-items-from-a-container
Happy New Year!
-Joe
 

________________________________

From: osg-users-bounces at lists.openscenegraph.org on behalf of Gordon Tomlinson
Sent: Thu 1/3/2008 8:43 AM
To: 'OpenSceneGraph Users'
Subject: Re: [osg-users] Error: 'Debug Assertion Failure!'


You might also want to see if the parent has any children first, as  we know has a getChildIndex slight bug in that it returns zero even if there are no children which is a valid index ..
 
osg::Group* root = (*ponto_itr)->getParent(0); 
 
if( root && root->getNumChildren() > 0 ) {
    root->removeChild(root->getChildIndex((*ponto_itr)), 1);
   }
 

or you could also do something like  as remove child with a node as does the right thing and the getChildIndex  bug does not come into play the way it is written
 
osg::Group* root = (*ponto_itr)->getParent(0); 
 
if( root ) {
  
    osg::Node* node = *ponto_itr;
    if( node )
        root->removeChild(node);
   }

the you would need to erase the ponto_itr, your logic for your loop will need to change as the interators will be invalidated when you use erase so you will need to update them your self
 
 

__________________________________________________________
Gordon Tomlinson 

Email   : gordon at GordonTomlinson.com
Website : www.vis-sim.com www.gordontomlinson.com 

__________________________________________________________

"Self defence is not a function of learning tricks 
but is a function of how quickly and intensely one 
can arouse one's instinct for survival" 
-Master Tambo Tetsura 

 

________________________________

From: osg-users-bounces at lists.openscenegraph.org [mailto:osg-users-bounces at lists.openscenegraph.org] On Behalf Of Gordon Tomlinson
Sent: 03 January 2008 16:08
To: 'OpenSceneGraph Users'
Subject: Re: [osg-users] Error: 'Debug Assertion Failure!'


I think you need to set your  (*ponto_itr) to NULL or remove it from the vector after you have done the remove child, other wise the pointer still has the address of the child you previously removed so you for loop above (ponto_limp) will never do any thing
 
 
 

__________________________________________________________
Gordon Tomlinson 

Email   : gordon at GordonTomlinson.com
Website : www.vis-sim.com www.gordontomlinson.com 

__________________________________________________________

"Self defence is not a function of learning tricks 
but is a function of how quickly and intensely one 
can arouse one's instinct for survival" 
-Master Tambo Tetsura 

 

________________________________

From: osg-users-bounces at lists.openscenegraph.org [mailto:osg-users-bounces at lists.openscenegraph.org] On Behalf Of Renan Mendes
Sent: 03 January 2008 14:43
To: OpenSceneGraph Users
Subject: [Norton AntiSpam] Re: [osg-users] Error: 'Debug Assertion Failure!'


Hi, Rafa,

        I've tried doing something like what you've said before: every time before I checked for selections with verifySelection(), I searched for a NULL member and erased it, like it's done below. Can you tell me why it still isn't working? Is there a logical flaw in my code? 

       Thanks,
           Renan M Z Mendes

        case(osgGA::GUIEventAdapter::KEYDOWN):
            {
                if(!ponto.empty())
                {
                    for(ponto_limp = ponto.begin(); ponto_limp != ponto.end(); ponto_limp++)
                    {
                        if(*ponto_limp == NULL)
                        {
                            ponto.erase(ponto_limp);
                        } 
                    }

                    for(ponto_itr = ponto.begin(); ponto_itr != ponto.end(); ponto_itr++)
                    {
                        if((*ponto_itr)->verifySelection())
                        { 
                            switch(ea.getKey())
                            {
                            case(ea.KEY_Delete):
                                {
                                    osg::Group* root = (*ponto_itr)->getParent(0); 
                                    root->removeChild(root->getChildIndex((*ponto_itr)), 1);
                                }
                            }
                        }
                    } 
                }
           }

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/ms-tnef
Size: 12738 bytes
Desc: not available
Url : http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080103/683cb622/attachment.bin 


More information about the osg-users mailing list