When my program executes and hits this loop:
i = 0; for (vector<Particle>::iterator I = Particles.begin(); I != Particles.end(); I++) { bool Did_Surf = false; if (I->Invalidate() == false) { Apply_Surface(I->Get_X() , I->Get_Y() , I->Get_Picture() , Screen); Did_Surf = true; } if (I->Expire() == true) { if (Did_Surf == false) { if (Particles.size() > i) { I->Destroy_Surface(); Particles.erase(Particles.begin() + i); } } } i++; }
The value of I which is random due to overflowing will periodically trigger Particles.erase() which will crash due to overflowing. Why is I being iterated over the boundries of the vector. Particles is a vector of class Particle.