Exception thrown at 0x00007FF746DA221B SDL_game.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF
我正在尝试调试应用程序,并且不断收到此错误,并且我不知道如何解决它。在调试时,我发现错误的地方是函数parseObjects。它还从游戏对象工厂中调用一个create函数,如下所示...
{
std::map<std::string, BaseCreator*>::iterator it = m_creators.find(typeID);
1 2 3 4 5 6 7 8 9 | if (it == m_creators.end()) { std::cout <<"could not find type:" << typeID <<"\ "; return 0; } BaseCreator* pCreator = (*it).second; return pCreator->createGameObject();} |
此后,它调用创建者对象加载函数,该函数成功加载了参数,但是当它尝试将对象推回到向量中时,会收到上面指出的错误。
在0x00007FF746DA221B SDL_game.exe上引发的异常:0xC0000005:访问冲突读取位置0xFFFFFFFFFFFFFFFF。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | ... 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 ??? }` |
调试器在向量中转到此行...
{ // test if _Ptr points inside vector
return (_Ptr < this->_Mylast() && this->_Myfirst() <= _Ptr);
}
任何帮助和建议将不胜感激...
我认为可能会发生这种情况,因为您的向量pObjects尚未初始化或处于某种损坏的状态。