user245019
user245019

Reputation:

Erasing a pointer from a vector

I'm trying to erase a pointer to an object, but I keep crashing the console (PS2), I don't get any errors due to the way the console is set up, so I'm not quite sure what is going on.

I've listed the two lines that error, this didn't error until I added these lines.

    for(listIter = m_downDirectionList.begin(); listIter != m_downDirectionList.end(); listIter++)
    {
        Projectile* proj = dynamic_cast<Projectile*>(*listIter);

        if (proj->getZWorldCoord() >= (defaultLevelDepth + zOffset))
        {
            proj->getPoolOwner()->releaseAProjectile(proj);
            //(*listIter) = NULL; // THIS ERRORS, also tried = 0.
            //listIter = m_downDirectionList.erase(listIter); // THIS ALSO ERRORS
        }

        else
        {
            (*listIter)->update(camera, zOffset);
        }
    }

What am I doing wrong?

Thanks.

EDIT: Clarification, just having this line.

listIter = m_downDirectionList.erase(listIter);

this also errors.

Upvotes: 5

Views: 178

Answers (2)

Firas Assaad
Firas Assaad

Reputation: 25770

for(listIter = m_downDirectionList.begin(); listIter != m_downDirectionList.end(); )
    {
        Projectile* proj = dynamic_cast<Projectile*>(*listIter);

        if (proj->getZWorldCoord() >= (defaultLevelDepth + zOffset))
        {
            proj->getPoolOwner()->releaseAProjectile(proj);
            listIter = m_downDirectionList.erase(listIter);
        }

        else
        { //m_downDirectionList[p]->update(camera, zOffset);
            (*listIter)->update(camera, zOffset);
            listIter++
        }
    }

Upvotes: 5

JP19
JP19

Reputation:

  m_downDirectionList.erase (listIter);

Upvotes: 0

Related Questions