Removing Nodes...[SOLVED]

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
Ravi08
Posts: 249
Joined: Thu Jul 17, 2008 12:25 pm

Removing Nodes...[SOLVED]

Post by Ravi08 »

Firstly i would like to say sorry for askin this question and yes i hav looked though the forums.

I have a node

Code: Select all

scene::IAnimatedMeshSceneNode* Middle =
    smgr->addAnimatedMeshSceneNode(smgr->getMesh("../media/Custom Guns/Mp5/Middle.3ds"));
Which i want to remove completly from the scene.

I have tried both

Code: Select all

smgr->addToDeletionQueue(Middle);
and

Code: Select all

Middle->remove();
but both crash wen they r called. Also the second method removes the node then a sec later crashes.

This is the if statement which is located within if (device->isWindowActive())

Code: Select all

        if(spx >= 16 && !receiver.IsLeftMouseButtonDown())
        {
            Test->setVisible(true);
            //smgr->addToDeletionQueue(Middle);
            //Middle->remove();
        }
Thanks for ur help in advance
Last edited by Ravi08 on Fri Aug 28, 2009 6:45 pm, edited 1 time in total.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Maybe you accidentally try to remove it more than once? Set your variable to 0 after removing and check for not null before removing to make sure you don't do that.
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
Ravi08
Posts: 249
Joined: Thu Jul 17, 2008 12:25 pm

Post by Ravi08 »

The thing is the variable "spx" gets the position of another node, so wen the other node is position 16 then this node needs to get deleted.

Oh and thanks for the help
Ravi08
Posts: 249
Joined: Thu Jul 17, 2008 12:25 pm

Post by Ravi08 »

It works now, wen u said
Maybe you accidentally try to remove it more than once?
It got me thinkin so i created a bool variable and added that to the if statement and then once the node is deleted set the variable to true.

So thank u very much :P
david_at_bass
Posts: 3
Joined: Fri Apr 03, 2009 6:14 pm
Location: venezuela

Post by david_at_bass »

i wasnt looking for this exactly but i got some help, i need render in the scene just the nodes that where visibles to user, when i saw node->setVisible(false) it saved my life jejejejeje 8)
Devil Master
Posts: 81
Joined: Wed Apr 23, 2008 8:47 pm

Post by Devil Master »

CuteAlien wrote:Maybe you accidentally try to remove it more than once? Set your variable to 0 after removing and check for not null before removing to make sure you don't do that.
Weird, I was trying just that (deleting an object) and I included a check like the one you described, but the program keeps crashing. This is what I do:
- at the beginning of the main function, I declare a bool variable called objectexists and set it to true
- before the main loop, I load an object which variable is node[1]
- during the main loop (the condition is while(device->run())) I do this:

Code: Select all

if (keys[KEY_KEY_R])
{
 if (objectexists)
 {
  smgr->addToDeletionQueue(node[1]); 
  node[1]->remove();
  objectexists=false;
 }
}
but when I press R to remove the object referred to as node[1], the program immediately crashes. Why?

EDIT:
BTW, maybe it's unnecessary to say, this but the program crashes even if I modify the above mentioned piece of code like this:

Code: Select all

if (keys[KEY_KEY_R])
{
 if (node[1])
 {
  smgr->addToDeletionQueue(node[1]); 
  node[1]->remove();
  node[1]=0;
 }
}
If I check the existence of another object in the node array (one that has never existed), the condition is not executed, as expected. So what am I missing here?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

You should only call one - either remove or addToDeletionQueue. Otherwise you try to dropt the same object twice. remove does remove immediately while addToDeletionQueue will remove a node after the rendering. This is sometimes needed because an animator might want to remove it's own node - but only after it has finished it's own execution. So unless you have a special reason just use remove.
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
Devil Master
Posts: 81
Joined: Wed Apr 23, 2008 8:47 pm

Post by Devil Master »

I just made two tests where I use only one of the functions, but each time the end result is still a crash as soon as I press R.
Ravi08
Posts: 249
Joined: Thu Jul 17, 2008 12:25 pm

Post by Ravi08 »

soz m8 but im clueless bout that wat u hav wrote should work the only thing i got is:

Code: Select all

if (keys[KEY_KEY_R] && objectexists) 
{  
  node[1]->remove(); 
  objectexists=false; 
}
u can try it but probabs wont work
"Hey Baby Wobbling Wobbling"
-Russell Peters
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Does it crash already on first call? Maybe node[1] does not contain a valid pointer. Just calling remove() on a valid node will not crash, so there seems to be another problem. But would need to see more code to tell...
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
cheshirekow
Posts: 105
Joined: Mon Jul 27, 2009 4:06 pm
Location: Cambridge, MA

Post by cheshirekow »

Just a stupid suggestion, but have you checked to ensure that your node[] array contains 2 elements?
Post Reply