void FactorySystem::deleteObjectsToBeDeleted()
{
//Delete all objects in the ObjectsToBeDeleted list
std::vector<unsigned>::iterator it = objectsToBeDeleted.begin();
for(unsigned i = 0; i < objectsToBeDeleted.size(); i++)
{
GameObjectIDMapType::iterator it = gameObjectIDMap.find(objectsToBeDeleted[i]);
if(it == gameObjectIDMap.end())
std::cout << "Bad memory or double deletion error!" << std::endl;
else
{
//Delete it and remove its entry in the ID map
std::cout << (it->second->GetID()) << std::endl;
GameObject *object = it->second;
delete object;
gameObjectIDMap.erase(it);
}
}
//All objects to be delete have been deleted
objectsToBeDeleted.clear();
}
在我调用删除对象的行中,程序只是永远挂起,我无法弄清楚原因。我搜索了这个问题,就像没有人曾经遇到过这个问题。我一定做坏事,但我不知道它会是什么。有任何想法吗?感谢。
编辑:
我被要求显示GameObject的析构函数,这里是:
GameObject::~GameObject()
{
//Delete each component using the component's virtual destructor
//takes care of all resources and memory.
for( ComponentMapIt it = componentMap.begin();it!=componentMap.end();++it)
delete it->second;
}
还有一件事,我进入了反汇编,并且能够一直走到:
00488DA9 call GameObject::`scalar deleting destructor' (044055Fh)
然后它就会挂起,没有其他事情发生。
编辑:这是我的菜鸟错误。出于某种原因,我无法进入删除调用,因此我认为它在那里,但是在其中设置一个断点允许我进入它。谢谢大家,您的所有建议都非常有用。void PhysicsManager::Unregister(RigidBody *Obj)
{
std::list<RigidBody*>::iterator it = MasterList.begin();
while(it != MasterList.end())
{
if(*it == Obj)
{
MasterList.erase(it);
return;
}
}
}
答案 0 :(得分:2)
void PhysicsManager::Unregister(RigidBody *Obj)
{
std::list<RigidBody*>::iterator it = MasterList.begin();
while(it != MasterList.end())
{
if(*it == Obj)
{
MasterList.erase(it);
return;
}
}
}
它是不变的,永远不会改变:一旦循环开始, *它!= Obj ,循环将永远持续