Quantcast
Channel: Parallel Computing in C++ and Native Code forum
Viewing all articles
Browse latest Browse all 856

std::vector overflows array

$
0
0

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. 


Viewing all articles
Browse latest Browse all 856

Latest Images

Trending Articles



Latest Images