//The horde is defined as so:
std::list<zombie*> horde;
typedef std::list<zombie*>::iterator hordeIt;
//Update the zombies
for (hordeIt zIt=horde.begin(); zIt !=horde.end(); ++zIt)
{
//The zombie will know if it should die. If a zombie returns DELETE, remove the list item
if ((*zIt)->onUpdate()==DELETE) //Note that DELETE is just #define DELETE 1, and that under Windows I had to rename it to DELETE_D due to some error (which didn't help anything)
{
delete (*zIt);
horde.erase(zIt);
//Make sure we don't try to access a nonexistent location
--zIt;
continue;
}
(*zIt)->onRender();
//Resolve health events with collisions (More zombie stuff here) ...
}
//New zombies are created like so:
horde.push_back(new zombie(/*various args*/));
When I lint the code with CppCheck I get "Dereferenced iterator zIt has been deleted", but it compiles fine under GCC and MinGW for Windows. No crashes occur under Linux but the Windows build crashes very frequently.
Here are the questions I have regarding this code:
- Do I need to use a separate iterator for the deletion of zIt?
- Is it alright if I continue to use the STL heavily? (I actually made my own doubly linked list and replaced the STL list in the same project as a test but it had phantom segfaults and thread sync errors [despite the project being single-threaded])
- Why do you think this code worked on Linux but not on Windows?