Original Post
Hi I am using a vector for storing bullets in my game. Every time the player fires his weapon a bullet object is added to this vector. Of course when a bullet collides with something i.e a wall or another player i need to remove that bullet from the vector. This is where i have the problem. When i delete the bullet from the vector, my game ends up in an infinite loop! The bullet class has a boolean attribute called "bulletCollided". This is set to true when the bullet has collided with a wall. So the following code loops through the vector list and attempts to delete any bullets which have collided: std::vector bulletList; if(bulletList.size() > 0) { for(std::vector::iterator i = bulletList.begin(); i != bulletList.end(); i++) { Bullet* bullet = *i; bullet->Update(map, elapsedTicks); if(bullet->HasBulletCollided()) { // bullet has collided so remove it from the list // delete the bullet object delete bullet; // remove from the list bulletList.erase(i); } } } Could someone please point out what i am doing wrong here. I am quite new to C++ programming. Thanks.