Hi,
We¡re getting a segmentation fault because we¡re trying to delete elements from a List while traversing it, i.e.:
We¡re getting a segmentation fault because we¡re trying to delete elements from a List while traversing it, i.e.:
Code:
void Character::deleteProcessed(list<Line> &active,int y){
bool erasedAtTheEnd = false;
for (list<Line>::iterator it = active.begin();it != active.end()&&!erasedAtTheEnd;){
if (it->getHighPoint().getY() < (HeightFloat/Height)*(y+1)){
Line aux = *it;
it++;
//In case you try to delete the final element , it != end doesn't
//stop the loop
if (it==active.end())
erasedAtTheEnd = true;
active.remove(aux);
}
else it++;
}
}
Comment