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?