From c2ece26130c6d951334f65518d0ec612197b0237 Mon Sep 17 00:00:00 2001 From: Mntndew Date: Mon, 16 Jun 2014 10:02:45 +0200 Subject: [PATCH] Fixed particle memory leak. --- Client/Client/ParticleEmitter.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Client/Client/ParticleEmitter.cpp b/Client/Client/ParticleEmitter.cpp index c2a2d3d..3e35a60 100644 --- a/Client/Client/ParticleEmitter.cpp +++ b/Client/Client/ParticleEmitter.cpp @@ -21,27 +21,28 @@ void ParticleEmitter::update(sf::Time & p_deltaTime){ m_vertexArray.append(m_particles[i].trail->getVertex()); }else { + delete m_particles[i].trail; m_particles.erase(m_particles.begin() + i); } } } void ParticleEmitter::Emit(const std::string & p_type, const sf::Vector2 & p_position, const sf::Vector2 & p_velocity){ - Particle* particle = new Particle(p_type, ptr_particleLoader->getParticleType(p_type), p_position, p_velocity); - m_particles.push_back(*particle); + Particle particle = Particle(p_type, ptr_particleLoader->getParticleType(p_type), p_position, p_velocity); + m_particles.push_back(particle); } void ParticleEmitter::Emit(const std::string & p_type, const sf::Vector2 & p_position){ sf::Vector2 velocity = sf::Vector2((((float)math::random(0, 100))/100)*(math::random(-1, 1, 0)), (((float)math::random(0, 100))/100)*(math::random(-1, 1, 0))); - Particle* particle = new Particle(p_type, ptr_particleLoader->getParticleType(p_type), p_position, velocity); - m_particles.push_back(*particle); + Particle particle = Particle(p_type, ptr_particleLoader->getParticleType(p_type), p_position, velocity); + m_particles.push_back(particle); } void ParticleEmitter::Emit(const std::string & p_type, const sf::Vector2 & p_position, const sf::Vector2 & p_velocity, const int & p_amount){ for (int i = 0; i < p_amount; i++) { - Particle* particle = new Particle(p_type, ptr_particleLoader->getParticleType(p_type), p_position, p_velocity); - m_particles.push_back(*particle); + Particle particle = Particle(p_type, ptr_particleLoader->getParticleType(p_type), p_position, p_velocity); + m_particles.push_back(particle); } } @@ -49,8 +50,8 @@ void ParticleEmitter::Emit(const std::string & p_type, const sf::Vector2 for (int i = 0; i < p_amount; i++) { sf::Vector2 velocity = sf::Vector2(((((float)math::random(1, 100))/100)*(math::random(-1, 1, 0))), ((((float)math::random(1, 100))/100)*(math::random(-1, 1, 0)))); - Particle* particle = new Particle(p_type, ptr_particleLoader->getParticleType(p_type), p_position, velocity); - m_particles.push_back(*particle); + Particle particle = Particle(p_type, ptr_particleLoader->getParticleType(p_type), p_position, velocity); + m_particles.push_back(particle); } }