大家好,我的食人魔问题有问题。我不确定这是否是问这个问题的最佳地点,但我也可以。这是我为创建 2D 敌人数组而编写的代码示例(用于太空入侵者游戏
for(int i = 0; i < 5; i++) //Manages the YPOS coordinate of the enemy
{
for(int j = 0; j < 5; j++) //Manages the YPOS coordinate of the enemy
{
stringstream ss;
ss << j;
std::string pos = ss.str();
ss.clear();
ss << i;
pos += "," + ss.str();
std::string enemyName = "Enemy " + pos;
Ogre::Entity * enemyEnt = mSceneMgr->createEntity(enemyName, "razor.mesh");
Ogre::SceneNode *node1 = mSceneMgr->getRootSceneNode()->createChildSceneNode (enemyName+"ParentNode");
Ogre::SceneNode *node2 = node1->createChildSceneNode(enemyName+"Node");
enemyEnt->setMaterialName("Examples/Chrome");
mSceneMgr->getSceneNode(enemyName+"Node")->attachObject(ent);
int multiplier = 100;
if(j < 3)
{
multiplier *= -1;
}
if(j == 3)
{
multiplier = 0;
}
Vector3 initialPos;
initialPos.x = (j+1) * multiplier;
initialPos.y = 0;
initialPos.z = 3000 - ((i+1) * multiplier);
enemyVec.push_back(new Enemy(mSceneMgr,node2, initialPos, j, i, 200 ));
}
}
enem->setEnemies(enemyVec);
}
以下是我得到的错误
C00146012 项目中 0x59a6ad4e (msvcp100d.dll) 处未处理的异常 - 3D Space Invaders.exe:0xC0000005:访问冲突读取位置 0xcccccd24。
调试时,它会将其带到 xutility 中的这段代码中
#if _ITERATOR_DEBUG_LEVEL == 2
if (_Myproxy != 0)
{ // proxy allocated, drain it
_Lockit _Lock(_LOCK_DEBUG);
for (_Iterator_base12 **_Pnext = &_Myproxy->_Myfirstiter; *_Pnext != 0; *_Pnext = (*_Pnext)->_Mynextiter)
(*_Pnext)->_Myproxy = 0;
_Myproxy->_Myfirstiter = 0;
}
#endif /* _ITERATOR_DEBUG_LEVEL == 2 */
但是我知道错误就在这条线上:
enem->setEnemies(enemyVec);
任何和所有的帮助将不胜感激:)