0
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)  

然后它只是挂起,没有其他任何事情发生。

编辑:这是我的菜鸟错误。出于某种原因,我无法进入 delete 调用,所以我认为它在那里,但是在其中设置一个断点允许我进入它。谢谢大家,您的所有建议都非常有帮助。

void PhysicsManager::Unregister(RigidBody *Obj)
{
  std::list<RigidBody*>::iterator it = MasterList.begin();

  while(it != MasterList.end())
  {
    if(*it == Obj)
    {
      MasterList.erase(it);
      return;
    }
  }
}
4

1 回答 1

2
void PhysicsManager::Unregister(RigidBody *Obj)
{
  std::list<RigidBody*>::iterator it = MasterList.begin();

  while(it != MasterList.end())
  {
    if(*it == Obj)
    {
      MasterList.erase(it);
      return;
    }
  }
}

是恒定的并且永远不会改变:一旦循环开始并且*it != Obj循环将永远继续

于 2013-10-18T07:07:25.287 回答