This is probably crashing when you remove the last element in openList.
This is what's happening:
1)
it2 = openList.erase( <lastElement> );
. erase returns an iterator that is one past the removed element. So if you just removed the last element, it2 now == openList.end()
2) the for loop then increments it2. it2 becomes invalid.
3) it2 is invalid and no longer == openList.end, so the for loop does not exit.
4) loop body attempts to dereference it2, resulting in a crash (if not the first time, then one of the many, many, many times the loop will continue)
As a general rule... if you are removing elements from a container... you do not want to use a for loop (for this very reason). You want to use a while loop:
1 2 3 4 5 6 7 8 9 10 11
|
for(it = closedList.begin(); it != closeList.end(); ++it)
{
it2 = openList.begin();
while( it2 != openList.end() )
{
if( ... want to remove element... )
it2 = openList.erase(it2);
else
++it2;
}
}
|