我正在尝试擦除指向对象的指针,但是我一直在崩溃控制台(PS2),由于控制台的设置方式我没有出现任何错误,所以我不太确定发生了什么.
我列出了两行错误,直到我添加这些行才出错.
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);
}
}
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
谢谢.
编辑:澄清,只是有这条线.
listIter = m_downDirectionList.erase(listIter);
Run Code Online (Sandbox Code Playgroud)
这也是错误.
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++
}
}
Run Code Online (Sandbox Code Playgroud)