1

I'm getting a "incompatible vector iterator" error to what i believe is a invalid iterator

void Bomb::CreateExplosion(Game_Manager* EGame_Manager)
{
for(irr::f32 iteration = 0; iteration < BlastRadius; iteration++) //up direction blast
{
   ***//PROGRAM CRASHES AT THIS LINE-->*** for(EGame_Manager->getEntityManager()->GetEntityIterator() = EGame_Manager->getEntityManager()->GetEntityList().begin(); EGame_Manager->getEntityManager()->GetEntityIterator() != EGame_Manager->getEntityManager()->GetEntityList().end(); ++EGame_Manager->getEntityManager()->GetEntityIterator())
    {
        if(CheckForCollision(UpExplosion->getTransformedBoundingBox(), (*EGame_Manager->getEntityManager()->GetEntityIterator())->GetEntityNode()->getTransformedBoundingBox()) == true)//check for collision against the unbreakable blocks (entity.type equals 0)
        {
            if((*EGame_Manager->getEntityManager()->GetEntityIterator())->GetType() == unbreakableblock)
            {
                break;
            }
            else if((*EGame_Manager->getEntityManager()->GetEntityIterator())->GetType() == gameplayer)
            {
                (*EGame_Manager->getEntityManager()->GetEntityIterator())->SetLives(this->GetLives() -1);
                break;
            }
            else if((*EGame_Manager->getEntityManager()->GetEntityIterator())->GetType() == gameitem)
            {
                break;
            }
        }
        else
        {
            UpExplosion->setScale(irr::core::vector3df(1,1,iteration)); //standard width of UpExplosion, iterated height of the UpExplosion
        }
    }
}

CreateExplosion is called by Bomb::UpdateEntity() which is called by EntityManager::UpdateList() which then loops through the vector<*Entity> List calling each Entity's respective Update function.

This function adds the Entities to the vector I'm not sure if it causes the problem

EntityManager::AddEntity(Entity* addtoList)
{
    List.push_back(addtolist);
    addtolist->GetEntityNode()->setID(List.size());
    EntityIterator = List.begin();
}

Also the instance of the Bomb class that calls these functions is declared in the Player class if that helps with anything. And I can post more code if needed.

  • Is this a compiler error or a runtime error? Also, without the definitions of the types, this is going to be tricky... – Oliver Charlesworth Jun 08 '11 at 00:30
  • if your `GetEntityIterator()` method returns a reference then the code _might_ make sense. – Cheers and hth. - Alf Jun 08 '11 at 00:35
  • Does AddEntity() get called at some point during the loop? Looks like the iterator is being set back to the beginning of the vector when a new entity is added... that might cause some strange side effects if you're already iterating through the list of entities. – Mike O'Connor Jun 08 '11 at 00:58
  • Does this occur on the first iteration, or on a later iteration? If it's a later iteration, what happens if you comment out some of the content of the loop body? – Oliver Charlesworth Jun 08 '11 at 00:59
  • 2
    Also, from a readability standpoint, the code would be much easier to follow if all the `EGame_Manager->getEntityManager()->GetEntityIterator()` instances were replaced with a local reference. – Mike O'Connor Jun 08 '11 at 01:00
  • Following on from that last comment, from a readability standpoint, I also wish people would fix their line lengths! In my opinion should be no more than 80 chars IMO so it's printable, or viewable in terminals. I could tolerate 120 but this side scrolling is ridiculous. –  Jun 08 '11 at 01:39
  • @Oli Charlesworth it happens on the first iteration – thatguyoverthere Jun 08 '11 at 01:50
  • @Mike O'Connor no the entire function finishes before another AddEntity() is called. – thatguyoverthere Jun 08 '11 at 01:54
  • Ok I changed the GetEntityList() and GetEntityIterator() to return a reference and now it crashes at runtime saying vector iterator not incrementable – thatguyoverthere Jun 08 '11 at 02:21
  • Can you replace the code that's there now with the new code? Also it would help to see the signatures of GetEntityList() and GetEntityIterator(). – Mike O'Connor Jun 08 '11 at 04:21
  • @Mike O'Connor I ran the debug and found out I just needed to rearrange the code a bit and got it to work. Thanks for the help. – thatguyoverthere Jun 08 '11 at 04:52

0 Answers0