some debugging help...

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
thatdudeoverthere
Posts: 28
Joined: Fri Apr 24, 2009 2:43 pm
Location: over there...

some debugging help...

Post by thatdudeoverthere »

I'm having some trouble with the runtime error "vector iterator not incrementable" I've ran through the call stack and I think I have it narrowed down, I just can't figure out why I'm getting this error.

Here are the functions that get called prior to the crash

Code: Select all

/////////////Entity.cpp/////////////////////////

Player::Player()
{
	PlayerBomb      = new Bomb;
	Type            = gameplayer;
	lives           = 3;
}

void Player::CreateEntity(Game_Manager* EGame_Manager, irr::core::vector3df EPosition)
{
	//Irrlicht member aspects of this class
	EntityMesh = EGame_Manager->getIrrScene()->getMesh("Bomb.obj");
	EntityNode = EGame_Manager->getIrrScene()->addAnimatedMeshSceneNode(EntityMesh);
	EntityNode->setPosition(irr::core::vector3df(0,1,0));

	//Class member aspects of this class
	EGame_Manager->getEntityManager()->AddEntity(this);
}

void Bomb::CreateEntity(Game_Manager* EGame_Manager, irr::core::vector3df EPosition)
{
	//Irrlicht member aspect of the class
	EntityMesh     = EGame_Manager->getIrrScene()->getMesh("Bomb.obj");
	EntityNode     = EGame_Manager->getIrrScene()->addAnimatedMeshSceneNode(EntityMesh);
	EntityNode->setPosition(EPosition);

	//Class member aspects of the class
	EGame_Manager->getEntityManager()->AddEntity(this);
    Activated = true;
    Timer     = 25; // before explosion
}

void Player::UpdateEntity(Game_Manager* EGame_Manager)
{
    MoveEntity(EGame_Manager);
}

void Player::MoveEntity(Game_Manager* EGame_Manager)
{
	if(EGame_Manager->KeyboardEvent(irr::KEY_SPACE))
	{
		//create the bomb
		if(PlayerBomb->isActivated() == false && PlayerBomb->isDestroyed() == false)
		{
		PlayerBomb->CreateEntity(EGame_Manager, EntityNode->getPosition());
		}
	}

}

Code: Select all

/////////////Entity_Manager.cpp/////////////////////////

void Entity_Manager::AddEntity(Entity* addtolist)
{
     List.push_back(addtolist);
	 addtolist->GetEntityNode()->setID(List.size());
}

void Entity_Manager::UpdateList(Game_Manager* EGame_Manager)
{
    for(EntityIterator = List.begin(); EntityIterator != List.end(); ++EntityIterator)
    {
        (*EntityIterator)->UpdateEntity(EGame_Manager);
    }
}

Code: Select all


///////////////Game_Manager.cpp////////////////////////

void Game_Manager::Update()
{
	//begin drawing the scene
	Driver->beginScene(true, true, irr::video::SColor(255, 100, 101, 140));

	//update game entities
    EntityManager->UpdateList(this);

	//draw all in the scene manager
	SceneMgr->drawAll();

	//clean up the scene for the next rendering
	Driver->endScene();
}

Here's the call stack in descending order

Player->CreateEntity()
Entity_Manager->AddEntity()
Game_Manager->Update()
Entity_Manager->UpdateList()
Player->UpdateEntity()
Player->MoveEntity()
Bomb->CreateEntity()
Entity_Manager->AddEntity()
Game_Manager->Update()
Entity_Manager->UpdateList() <----Crashes here Runtime Error "Vector Iterator not incrementable"

Any help is appreciated. :)
//Personal code

bool sarcasm;

void set_sarcastic()
{
sarcasm = true;
}
[img]
http://imgs.xkcd.com/comics/goto.png
[/img]
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Post by Radikalizm »

I assume that since it's possible in your code to add an element to your list while iterating through that list that you are invalidating your iterator, ie. when calling List.push_back(...) your iterator will become invalid because the structure of your list has changed
thatdudeoverthere
Posts: 28
Joined: Fri Apr 24, 2009 2:43 pm
Location: over there...

Post by thatdudeoverthere »

So how should I go about this?
Should I have the iterator point to the beginning of the list after it add an element to the list?

Code: Select all

List.pushback(...);
EntityIterator = List.begin();
Or will that just cause EntityIterator to point to the beginning of a changed list causing it to still be invalid?
//Personal code

bool sarcasm;

void set_sarcastic()
{
sarcasm = true;
}
[img]
http://imgs.xkcd.com/comics/goto.png
[/img]
Post Reply