Hello, sorry for the thread hijack but since my question falls under the same topic I think it's ok to ask here.
I'm trying to implement a particle system based on the example provided by Laurent, but I'm having a bit of trouble erasing a particle when requested. So far I'm doing it like this:
//Inside the particle system class
std::vector<Particle> m_vectorParticle; //Holds the particles
std::vector<sf::Vertex> m_vectorVertex; //The vertex array
...
void update()
{
for(unsigned int i = 0; i < m_vectorParticle.size(); ++i)
{
m_vectorParticle[i].update(&m_vectorVertex[i * 4], 1);
if(//It's time to delete the particle)
{
m_vectorParticle.erase(m_vectorParticle.begin()+i);
m_vectorVertex.erase(m_vectorVertex.begin()+i);
m_vectorVertex.erase(m_vectorVertex.begin()+i+1);
m_vectorVertex.erase(m_vectorVertex.begin()+i+2);
if(m_vectorVertex.erase(m_vectorVertex.begin()+i+3) == m_vectorVertex.end())
return;
}
}
}
However when it's time to erase a particle, the application seems to freezes and I'm not sure why. I don't believe I'm accessing or erasing anything invalid, or maybe I'm just being silly?
Could someone give me a tip to do this correctly?
Thanks,
Best regards.