ParticleEffectEntityItem: fix for invalid iterator increment

Was causing an assert in debug, due to calling ++ on an invalid iterator.
In release this might lead to memory corruption.
This commit is contained in:
Anthony J. Thibault 2015-12-16 16:56:49 -08:00
parent 29516619ee
commit 1b08563079

View file

@ -595,19 +595,24 @@ void ParticleEffectEntityItem::integrateParticle(Particle& particle, float delta
void ParticleEffectEntityItem::stepSimulation(float deltaTime) {
// update particles between head and tail
int popCount = 0;
for (Particle& particle : _particles) {
particle.lifetime += deltaTime;
// if particle has died.
if (particle.lifetime >= _lifespan) {
// move head forward
_particles.pop_front();
popCount++;
} else {
// Otherwise update it
integrateParticle(particle, deltaTime);
}
}
for (int i = 0; i < popCount; i++) {
_particles.pop_front();
}
// emit new particles, but only if we are emmitting
if (getIsEmitting() && _emitRate > 0.0f && _lifespan > 0.0f && _polarStart <= _polarFinish) {