Every time the player crosses to a different tile, the new tile's onEnter() gets called and the old tile's onExit() gets called
Each tile object has std::set that stores all the entities that are on the tile. onEnter() adds the pointer to the entity to its set and onExit() erases the pointer from its set.
But my game crashes there.
[source lang="cpp"] //Check if the player moved to a different tile if(previousLoc!=currentLoc) { gameWorld->getGameMap().onEnter(currentLoc.x, currentLoc.y, this); gameWorld->getGameMap().onExit(previousLoc.x, previousLoc.y, this); } GameMap::onEnter(int x, int y, Entity * e) { tiles[y][x].onEnter(e); } GameMap::onExit(int x, int y, Entity *e) { tiles[y][x].onExit(e); } Tile::onEnter(Entity * e) { entities.insert(e); //entities is declared as std::set<Entity*> entities } Tile::onExit(Entity * e) { entities.erase(e); } [/source]
The stack trace shows up like this
> Game3.exe!std::_Tree<std::_Tset_traits<Entity *,std::less<Entity *>,std::allocator<Entity *>,0> >::_Root() Line 2139 C++
Game3.exe!std::_Tree<std::_Tset_traits<Entity *,std::less<Entity *>,std::allocator<Entity *>,0> >::_Insert_nohint<Entity * const &,std::_Nil>(bool _Leftish, Entity * const & _Val, std::_Nil _Newnode) Line 1784 C++
Game3.exe!std::_Tree<std::_Tset_traits<Entity *,std::less<Entity *>,std::allocator<Entity *>,0> >::insert(Entity * const & _Val) Line 1304 C++
Game3.exe!std::set<Entity *,std::less<Entity *>,std::allocator<Entity *> >::insert(Entity * const & _Val) Line 166 C++
Game3.exe!Tile::onEnter(Entity * e) Line 17 C++
Game3.exe!GameMap::onEnter(int x, int y, Entity * e) Line 118 C++
What can possibly cause my program to crash?
Edited by lride, 09 December 2012 - 08:34 PM.






