Original Post
I have a vector of pointer to entity. I also have a GameWorld class that contains this vector.
[source lang="cpp"]std::vector entities;
GameWorld::GameWorld()
{
entities.push_back(new Character("YOURS", CharacterType::BLACK));
}
GameWorld::~GameWorld()
{
for(auto e: entities)
delete e;
}[/source]
When I close the game I get assertion failure "vector subscript out of range". What did I do wrong?
Edit:
I still get the vector assertion failure even when I changed the std::vector to std::list
I also found out that I can use the std::vector even I don't #include
OK I solved my problem. The GameWorld object is inside Game class which is a singleton. So the GameWorld is statically allocated.
But when I allocated Game class on stack, it worked fine. I have no idea why..
[source lang="cpp"]std::vector
GameWorld::GameWorld()
{
entities.push_back(new Character("YOURS", CharacterType::BLACK));
}
GameWorld::~GameWorld()
{
for(auto e: entities)
delete e;
}[/source]
When I close the game I get assertion failure "vector subscript out of range". What did I do wrong?
Edit:
I still get the vector assertion failure even when I changed the std::vector to std::list
I also found out that I can use the std::vector even I don't #include
OK I solved my problem. The GameWorld object is inside Game class which is a singleton. So the GameWorld is statically allocated.
But when I allocated Game class on stack, it worked fine. I have no idea why..