c++c++11vectortinyxml

Exception thrown at 0x00007FF746DA221B SDL_game.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF


I am trying to debug my application and I constantly receive this error and I don't know how to fix it. While debugging I found out that the place of the error is the function parseObjects. It also invokes a create function from the game object factory which is as follows ...

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();}

After this it invokes a Creator objects load function which loads the parameters successfully, but when it tries to push the object back into the vector it receive the up stated error.

Exception thrown at 0x00007FF746DA221B SDL_game.exe: 0xC0000005: Access violation reading location 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 ???
}`

The debugger goes to this line in vector... bool _Inside(const value_type *_Ptr) const { // test if _Ptr points inside vector return (_Ptr < this->_Mylast() && this->_Myfirst() <= _Ptr); }

Any help and suggestions will be appreciated...


Solution

  • I think this could happen because your vector pObjects is not initialised or in some kind of a corrupted state.