Page 1 of 1

Removing scene nodes.

Posted: Wed Oct 26, 2005 6:22 pm
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

Posted: Wed Oct 26, 2005 7:01 pm
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.

Posted: Sun Oct 30, 2005 5:25 pm
by WToma
Doesn'r crash, worse :D None of the objects will be displayed... But all works well when using setPosition line...
Toma