Repeat inside my application

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
ibax
Posts: 193
Joined: Thu Jun 21, 2007 8:56 am
Location: hungary
Contact:

Repeat inside my application

Post by ibax »

Hello,

My app contain a menu and the game currently in a 3D environment.
When I go fro Menu to Game, that is OK. After I go back to MENU. Still OK. But when I try to go again from the Menu to the GAME, my application is crashing (in the loading phase)...

I tried to do a clear() for my environment and also for the scene manager, but it is still crashing.

What are the basic methods, when trying to make a "loop" (play again) inside the app? Which pointers should I delete? I'm asking it in a general way.

My app is crashing here...

Code: Select all

 
metaSelector = smgr->createMetaTriangleSelector();
 
XenoZergNid
Posts: 17
Joined: Sun Oct 13, 2013 1:52 am

Re: Repeat inside my application

Post by XenoZergNid »

I havn't used IMetaTriangleSelectors yet but
I think you need to call this: metaSelector->removeAllTriangleSelectors
ibax
Posts: 193
Joined: Thu Jun 21, 2007 8:56 am
Location: hungary
Contact:

Re: Repeat inside my application

Post by ibax »

I located the problem, but unfortunately don't know the solution now...

A friend of mine was writing this code (not part of the project currently), so I'm just trying to figure out, what he tried to achive...
What I know, that this part goes through each element, which was located in the loaded irr file, and makes the possibility of collision with octree nodes.

This is a part of our recursiveFillMetaSelector function, where the problem is...

Code: Select all

    core::list<scene::ISceneNode*>::ConstIterator begin = node->getChildren().begin();
    core::list<scene::ISceneNode*>::ConstIterator end   = node->getChildren().end();
    
    for (; begin != end; ++begin)
    {
        recursiveFillMetaSelector(*begin, meta);
    }
 
The function is called in this way...

Code: Select all

metaSelector = smgr->createMetaTriangleSelector();
recursiveFillMetaSelector( smgr->getRootSceneNode(), metaSelector );
When I load my game FIRST time, everything is OK. When I go back to my menu and start my game AGAIN, I see that the loading of irr is simply skipped (is this normal behaviour, because the texture files and mesh files are in the memory?),so the loading process starts much faster, but it also creashes on that FillMetaSelector part...
CuteAlien
Admin
Posts: 9972
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Repeat inside my application

Post by CuteAlien »

Sorry, that's still not enough code for us to reproduce the problem. Those lines you posted simply go recursively over the scenegraph. That's fine.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
ibax
Posts: 193
Joined: Thu Jun 21, 2007 8:56 am
Location: hungary
Contact:

Re: Repeat inside my application

Post by ibax »

Hello,

I will try to give you more informations...

eventreceiver, this executes, when I click on the Start button to start my game:

Code: Select all

 
                    case 151:
                    {
                        textLog.writeLog("Button '151' clicked.");
                        env->clear();
                        loadExercise1(smgr,device,driver,env);
                        break;
                    }
 
loadExercise1 function

Code: Select all

 
void loadExercise1( ISceneManager* smgr, IrrlichtDevice *device, IVideoDriver * driver, IGUIEnvironment *env){
 
    smgr = device->getSceneManager();
    
    SKeyMap keyMap[8];  
    keyMap[0].Action = EKA_MOVE_FORWARD;
// (not relevant here...)
    keyMap[7].KeyCode = KEY_KEY_D;
 
    smgr->loadScene("models_materials\\game.irr");
    camera = smgr->addCameraSceneNodeFPS(0, 120.0f, 0.2f, -1, keyMap, 9, true,0.15f);
    f32 aspect = 1.f * driver->getScreenSize().Width / driver->getScreenSize().Height;
    camera->setRotation(core::vector3df(0,-90,0));  
    camera->setPosition(core::vector3df(0,80,0));
    camera->setFarValue(20000.0f);
    camera->setAspectRatio(aspect);
    camera->setFOV(2*PI/5); 
    metaSelector = smgr->createMetaTriangleSelector();
    recursiveFillMetaSelector( smgr->getRootSceneNode(), metaSelector );
    curs = smgr->addAnimatedMeshSceneNode(smgr->getMesh("cursors\\szines_babu_final.obj"),camera,-1,core::vector3df(0,3,20));
    curs->setScale(vector3df(0.075 , 0.075 , 0.075));
    curs->setMaterialFlag(video::EMF_LIGHTING,false);
    anim = smgr->createCollisionResponseAnimator(   metaSelector, camera, core::vector3df(20,36,20),
                                                    core::vector3df(0,-10.0f,0),
                                                    core::vector3df(0,85,0));
 
    anim->setEllipsoidRadius( core::vector3df(10,36,10) );
    camera->addAnimator(anim);
    metaSelector->drop();
    admin.setEx1_ObjectsAndActivities();
    admin.Ex1_showElements();
    admin.Ex1_loadDistinctObjects( admin.patientID );                           // SELECT DISTINCT -> to prevent multiple load of the same objects/activities
    device->getCursorControl()->setVisible(false);  
}
 
 

When I push the Q button to quit to the menu:

Code: Select all

 
            switch (event.KeyInput.Key)
            {
                case KEY_KEY_Q:
                {                   
                        IGUIEnvironment* env = device->getGUIEnvironment();
                        smgr->clear();
                        env->clear();
                        device->getCursorControl()->setVisible(true);
                }
                    return true;                    
                }
 
 

And when, here in the menu, When I click on start once again, the application creashes here:

Code: Select all

 
    recursiveFillMetaSelector( smgr->getRootSceneNode(), metaSelector );
 
The function:

Code: Select all

 
 
void recursiveFillMetaSelector(scene::ISceneNode* node, scene::IMetaTriangleSelector* meta )
{
  printf ("Node name is: %s \n",node->getName());
  printf ("Node id is: %d \n",node->getID());
  printf ("Node type:");
  
  if (node->getType() ==   ESNT_UNKNOWN) printf("Unknown mesh type \n\n");
  if (node->getType() ==   ESNT_MESH) printf("Standard Mesh \n\n");
  if (node->getType() ==   ESNT_ANIMATED_MESH) printf("Animated Mesh! \n\n");
  if (node->getType() ==   ESNT_SKY_BOX) printf("SkyBox! \n\n");
  if (node->getType() ==   ESNT_CAMERA_FPS) printf("Fps Camera! \n\n");
  if (node->getType() ==   ESNT_CAMERA_MAYA ) printf("Maya Camera! \n\n");
  if (node->getType() ==   ESNT_CAMERA )
  {
    printf("STD Camera! \n");
    camera->setPosition(node->getPosition());
  }
  if (node->getType() ==   ESNT_PARTICLE_SYSTEM ) printf("Particles! \n\n");
  if (node->getType() ==   ESNT_LIGHT  ) printf("Light! \n\n");
  if (node->getType() ==   ESNT_OCTREE)
  {
      printf("Occtree! \n");
      io::IAttributes* attribs = device->getFileSystem()->createEmptyAttributes();
      if (attribs)
      {
         node->serializeAttributes(attribs);
         core::stringc name = attribs->getAttributeAsString("Mesh");
         attribs->drop();
         scene::IAnimatedMesh* mesh = smgr->getMesh(name.c_str());
         if (mesh)
         { 
            selector = smgr->createOctTreeTriangleSelector(mesh->getMesh(0), node, 128);
            node->setTriangleSelector(selector);
            metaSelector->addTriangleSelector(selector);
            selector->drop();
         }
 
     }
     
  } 
 
  core::list<scene::ISceneNode*>::ConstIterator begin = node->getChildren().begin();
  core::list<scene::ISceneNode*>::ConstIterator end   = node->getChildren().end();
    
  for (; begin != end; ++begin)
  {
    recursiveFillMetaSelector(*begin, meta);
  }
}
 
 
 
CuteAlien
Admin
Posts: 9972
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Repeat inside my application

Post by CuteAlien »

Ok, not much time right now (at work) but didn't see anything wrong on a quick view. Is loadExercise1 really just a c-function and not a member-function of some class? Because it would make sense to crash at that point if it belongs in a class and the class-object itself isn't valid at this point.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply