Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actuallride

Posted 08 December 2012 - 01:20 PM

I have a vector of pointer to entity. I also have a GameWorld class that contains this vector.
[source lang="cpp"]std::vector<Entity*> 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 <vector>

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..

#3lride

Posted 08 December 2012 - 12:34 PM

I have a vector of pointer to entity. I also have a GameWorld class that contains this vector.
[source lang="cpp"]std::vector<Entity*> 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 <vector>

#2lride

Posted 08 December 2012 - 12:17 PM

I have a vector of pointer to entity. I also have a GameWorld class that contains this vector.
[source lang="cpp"]std::vector<Entity*> 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

#1lride

Posted 08 December 2012 - 11:48 AM

I have a vector of pointer to entity. I also have a GameWorld class that contains this vector.
[source lang="cpp"]std::vector<Entity*> 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 "vector subscript out of range". What did I do wrong?

PARTNERS