开发者

Erasing a pointer from a vector

开发者 https://www.devze.com 2023-01-27 16:12 出处:网络
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'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() >开发者_如何学Go= (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.


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++
        }
    }


  m_downDirectionList.erase (listIter);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号