c++ Access violation reading location while erasing from list -
i have following c++ code:
typedef std::list< volume >::iterator pvolume; typedef std::list< pvolume >::iterator ppvolume; void node::delvolume( pvolume _volume ) { for( ppvolume = m_volumes.begin( ); != m_volumes.end( ); ) if( (*it) == _volume ) { = m_volumes.erase( ); break; } else it++; } it gets error
unhandled exception @ 0x009a3c79 in delone3d.exe: 0xc0000005: access violation reading location 0xfeeefef2.
exactly when erasing. debug shows neither "it" nor "_volume" null pointer.
what other reasons may occur for?
the code show correct, seems there's problem elsewhere in application. memory pattern 0xfeeefef2 (a few addresses above 0xfeeefeee) indicates freed dynamic memory, see here.
you can massively simplify code, way:
// std::list, in example m_volumes.remove(_volume); // std::vector , std::deque auto itr = std::remove(m_volumes.begin(), m_volumes.end(), _volume); m_volumes.erase(itr, m_volumes.end());
Comments
Post a Comment