Removing scene nodes.

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
WToma
Posts: 70
Joined: Tue Aug 09, 2005 8:38 am
Location: Szeged, Hungary

Removing scene nodes.

Post by WToma »

I know that it will be trivial again :) But I just can't get it.

Code: Select all

struct A {
vector<ISceneNode*> nodes(0); //std lib vector
void update();
void run();
};

void A::run() {
while(device->run()) {
update();
}
}

void A::update() {
if(really_need_update) {
for(int i=0;i<nodes.size();i++) {
nodes[i]->remove(); //(1)
}
nodes.clear();
//fill 'nodes' with new scene nodes
}
driver->beginScene(...);
smgr->drawAll();
driver->endScene();
}
It should do the following: if the scene is need to be updated (a new car created, etc.) it deletes all scene nodes and fills 'nodes' with new ones. (I know that it is a bad idea anywy, but when I did this it wasn't possible to change anything but the visualisation code.)
But I cannot see anything. If remove line (1), it works, but those scene nodes that should not be seen, are still visible. I could solve this by replacing (1) with

Code: Select all

nodes[i]->setPosition(10000.0f,10000.0f,10000.0f);
but it is again a bad thing, because if I would use those part of the scene, there would be a problem, and it slows down the system.

So, what could be wrong with the code? (Nice question, isn't it ;))

Toma
"This is not a bug, this is a feature!"
pfo
Posts: 370
Joined: Mon Aug 29, 2005 10:54 pm
Location: http://web.utk.edu/~pfox1

Post by pfo »

What's the problem? Is it crashing? Maybe you're trying to remove an invalid node. I suggest that when you allocate the array of nodes, set them all to NULL first, that way if it crashes in the debugger you can find the problem node pretty easily. Also, as soon as you remove a node, set that pointer to NULL, again, makes it easier to find the problem node.
WToma
Posts: 70
Joined: Tue Aug 09, 2005 8:38 am
Location: Szeged, Hungary

Post by WToma »

Doesn'r crash, worse :D None of the objects will be displayed... But all works well when using setPosition line...
Toma
"This is not a bug, this is a feature!"
Post Reply