I´m trying to push new objects into a vector, that works. But when the object dies and I want to remove it something happens because after that if i try to spawn another object the program crashes.
std::vector<C_Entity*>::iterator it;
for(it = C_Entity::EntityList.begin(); it != C_Entity::EntityList.end();)
{
if ((*it)->Dead == true)
{
delete * it;
it = C_Entity::EntityList.erase(it);
}
else
{
it++;
}
}
Could someone pleeeeease tell me what is wrong? :(
As I said, the program seems to crash when I try to add a new object after another object has been destroyed.
It's actually quite simple (in theory). Basically, you can set a 'breakpoint' somewhere in your code so that when the program reaches that spot, it pauses and lets you see what all the variables and such are at that point. Then you can step line by line through the code and see where crash-causing values are coming from.
If nothing is colliding (or it least shouldn't be) I'd step up the call stack to see where the collision function is being called so you can see why it is being called.
Why is it crashing? Look at the state of the variables and the crash message and then figure out why/how the data is getting into the state in the first place.
I actually solved it now, and it was just out of pure luck. I had a Cleanup function call by mistake in a Class method that got called in the loop if the object was dead.