Cookie if someone can spot it. I'm scratching my head.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
void MapBlock::trimDeadEnds( wall_t& wall )
{
for(auto i = wall.begin(); i != wall.end(); ++i)
{
auto j = wall.end() - 1;
while( j > (i + c_DetItemsAhead) )
{
if( pointsWithinDistance( *i, *j, c_DetDistance ) )
{
i = wall.erase( i + 1, j ) - 1;
break;
}
else
--j;
}
}
}
|
wall_t is just a typedef of std::vector<some_type>
pointsWithinDistance doesn't do anything spectacular. It doesn't modify any passed params.
In MSVS 2010 Express... Release build works fine.
Debug build crashes on the call to erase() with an Assertion failure:
"Expression: vector iterator + offset out of range"
I don't see anything out of range here. Can somebody spot it?
It might be a bug in Visual Studio... but I *really* don't want to make that assumption unless I've ruled out all other avenues.
Thanks.
EDIT:
I suppose
i + c_DetItemsAhead
could be out of range.... (c_DetItemsAhead is ~6), but that wouldn't cause an issue in erase()... because if it's out of range the erase call won't happen.
EDIT 2:
Okay after commenting out the erase call, I'm also getting the same assertion failure on the
i + c_DetItemsAhead
line. Maybe I should rewrite this to use indexes instead of out-of-bound iterators....