Permalink
Browse files

Bug fix: invalid iterator dereferenced.

bear::universe::world_progress_structure used to store the iterator at the end
of the neighborhood before processing a loop which erases elements in the
neighborhood and thus invalidates the iterators.

Now we check the end iterator at each iteration.
  • Loading branch information...
Julien Jorge
Julien Jorge committed Oct 8, 2013
1 parent 60eb55a commit a1df4e13453d29d21e99702674f90a7821df5810
Showing with 4 additions and 9 deletions.
  1. +4 −9 bear-engine/core/src/universe/code/world_progress_structure.cpp
@@ -331,13 +331,12 @@ bear::universe::world_progress_structure::pick_next_neighbor()
*/
bool bear::universe::world_progress_structure::update_collision_penetration()
{
const item_list::iterator eit( m_collision_neighborhood.end() );
item_list::iterator it = m_collision_neighborhood.begin();
m_collision_mass = 0;
m_collision_area = 0;
while ( it != eit )
item_list::iterator it = m_collision_neighborhood.begin();
while ( it != m_collision_neighborhood.end() )
{
bool collision(false);
@@ -369,11 +368,7 @@ bool bear::universe::world_progress_structure::update_collision_penetration()
if ( collision )
++it;
else
{
item_list::iterator rit(it);
++it;
m_collision_neighborhood.erase(rit);
}
it = m_collision_neighborhood.erase( it );
}
return !m_collision_neighborhood.empty();

0 comments on commit a1df4e1

Please sign in to comment.