【发布时间】:2016-08-17 18:16:06
【问题描述】:
我正在尝试调试我的应用程序,但我不断收到此错误,但我不知道如何修复它。在调试时我发现错误的地方是函数 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);
}
任何帮助和建议将不胜感激......
【问题讨论】: