This is driving me nuts, so I came here.
Code:
class CTestTask : public ITask
{
public:
bool Start();
void Update();
void Stop();
private:
std::list < particle * > particles;
};
This is called every frame.
Code:
void CTestTask::Update()
{
for( int i = 0; i < (PARTICLES_ADDED_PER_SECOND+1; i++ )
particles.push_back( new SnowParticle );
for (std::list<particle*>::iterator part=particles.begin(); part != particles.end(); part++)
{
// We first test the particle to see if it should remain alive
//if (*part)
{
//(*part) = new SnowParticle;
if( (*part)->TestParticle() )
{
// If it should, we update and draw the particle
(*part)->UpdateParticle();
(*part)->DrawParticle();
// And then move onto the next particle
}
else
{
// If we end it here, then it continues until the point that it would have crashed, and stops making particles???
// Otherwise we cut the particle out of the list, and trash it.
delete (*part);
//particle * oldparticle = (*part);
particles.erase( part, part );
//delete oldparticle;
}
}
}
if (*part)->TestParticle() returns false, it should delete the memory for the particle and then delete the pointer from the linked list.
This causes a crash . If I don't free the memory from the new, then it works, but there's a memory leak...