异常抛出0x00007FF746DA221B SDL_game.exe:0xC0000005:访问冲突读取位置0xFFFFFFFFFFFFFFFF

时间:2016-04-24 11:00:09

标签: c++ c++11 vector tinyxml

我正在尝试调试我的应用程序而且我经常收到此错误,我不知道如何解决它。在调试时我发现错误的位置是函数parseObjects。它还从游戏对象工厂调用创建函数,如下所示......

GameObject* GameObjectFactory::create(std::string typeID) { std::map<std::string, BaseCreator*>::iterator it = m_creators.find(typeID);

if (it == m_creators.end()) 
{
    std::cout << "could not find type: " << typeID << "\n";
    return 0;
}

BaseCreator* pCreator = (*it).second;
return pCreator->createGameObject();}

在此之后,它调用一个Creator对象加载函数,该函数成功加载参数,但是当它试图将对象推回向量时,它会收到上述错误。

0x00007FF746DA221B处抛出异常SDL_game.exe:0xC0000005:访问冲突读取位置0xFFFFFFFFFFFFFFFF。

    ...
    e->Attribute("x", &x);
    e->Attribute("y", &y);
    e->Attribute("width", &width);
    e->Attribute("height", &height);
    e->Attribute("numFrames", &numFrames);
    e->Attribute("callbackID", &callbackID);
    e->Attribute("animSpeed", &animSpeed);

    type = e->Attribute("type");
    textureID = e->Attribute("textureID");

    GameObject* pGameObject = TheGameObjectFactory::Instance()->create(type);
    pGameObject->load(new LoaderParams(x, y, width, height, textureID, numFrames, callbackID, animSpeed)); 
    pObjects->push_back(pGameObject); // fails on this line ???
}`

调试器在向量中转到此行... bool _Inside(const value_type *_Ptr) const { // test if _Ptr points inside vector return (_Ptr < this->_Mylast() && this->_Myfirst() <= _Ptr); }

任何帮助和建议都将不胜感激......

1 个答案:

答案 0 :(得分:0)

我认为这可能是因为你的矢量pObjects没有初始化或处于某种破坏状态。