Reputation: 103
When I try to run my program I get 'map/set iterator not incrementable' error. I read that it happens when you invalidate iterator, but I'm only editing objects pointed by iterator. Is this normal behaviour? What can I do about it? If I delete this line then there is no error:
iterator->second.neighbour[direction] = &(find_iter->second);
Full code:
void Gomoku::addUniqueMap( const map_Map& map_to_add )
{
this->unique_maps.push_front( map_to_add );
std::list<map_Map>::iterator map_iter = this->unique_maps.begin();
map_Iterator iterator = map_iter->begin();
for( ; iterator != map_iter->end(); ++iterator )
{
for( int i = 1, direction = 0; i > -2; --i )
{
for( int j = -1; j < 2; ++j )
{
if( iterator->second.neighbour[direction] == nullptr )
{
++direction;
continue;
}
if( i == 0 && j == 0 )
continue;
COORD pos( iterator->first.x + j, iterator->first.y + i );
wrap( pos, this->map_size );
map_Iterator find_iter = map_iter->find( pos );
if( find_iter != map_iter->end() )
{
iterator->second.neighbour[direction] = &(find_iter->second);
}
++direction;
}
}
}
}
'map_Map' - std::map<COORD, Pawn>
'map_Iterator' - std::map<COORD, Pawn>::iterator
'Pawn' -
struct Pawn
{
Pawn( Player player );
Player player;
const Pawn* neighbour[8];
};
Upvotes: 0
Views: 1112
Reputation: 103
The cause of the error was that I was accessing and modifying neighbour[8]
, so I was modifying element of out array range and possibly it has done something to the iterator.
In Debug version I got map/set iterator not incrementable
error while in Release version iterator couldn't be incremented and it caused program to loop infinitely.
Upvotes: 0