Page 1 of 1

List iterators.

Posted: Mon Oct 15, 2007 6:50 pm
by bphillips
The code in the emulator has several loops like this:
for(iterator=clients.begin(); iterator!=clients.end(); iterator++){
}
If you change the iterator inside the loop, specifically, if you erase something from the loop, then reset the iterator to clients.begin() you will apply the ++iterator PRIOR to the conditional statment. If the list size has been changed to 0 this should throw an exception (maybe it doesnt with release compile on but it should...) at any length it is more stable to use one of the following options:
--two loops( easier and good for list that are expected to be short)
bool change = true;
while(change){
change=false;
for(i=list.beign; i!=list.end &&!change; i++){
if(){
//make erase
change=true;
}
}
}
--other option is to use a toRemove list

Posted: Mon Oct 15, 2007 8:36 pm
by Bafoon
Can someone explain this in human terms? I am always up for learning.

Posted: Tue Oct 16, 2007 4:32 am
by LethalEncounter
You are right but there are only a few locations in the code that dont exit the iterator if something was deleted from it. It will be fixed.