Domanda

Hi guys I'm having a problem in my Ogre problem. I'm not sure if this is the best place to ask this but I may as well. Here is the sample of the code I made in order to create a 2D array of enemies(for a space invaders game

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

The following is there error I'm getting

Unhandled exception at 0x59a6ad4e (msvcp100d.dll) in C00146012 Project - 3D Space Invaders.exe: 0xC0000005: Access violation reading location 0xcccccd24.

When debugging it brings it to this segment of code in 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 */

However I know the error is in the line:

enem->setEnemies(enemyVec);

Any and all help would be greatly appreciated :)

È stato utile?

Soluzione

What ever you want to do with the Entitys and Scene nodes, in this line

    enem->setEnemies(enemyVec);

remember that you declared the Nodes and the Entity just in the scope of the loop, and as you didnt made a full copy of them and pasted it into allocated memory, your vector is probably refering to the automatic allocated nodes out of their lifetime and whatever you are going to do with them, its undefined behaviour. So probably some states are still the same in their memory, and Ogre can work with them, but gets errors, because its not exactly that what its supposed to be.

And even if Ogre is handling this, you should notify that

for each

i;j == 3

the initial position is the same. So it could be as refering to the Ogre error, that if pos has anything to do with initialPos, you have non unique strings, where unique strings are expected.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top