IAnimatedSceneNode->remove() crash

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
LunaRebirth
Posts: 386
Joined: Sun May 11, 2014 12:13 am

IAnimatedSceneNode->remove() crash

Post by LunaRebirth »

Hello. Probably a simple solution here, but I'm not sure of it.
I'm trying to make it so you can grab a hat to place it on your player. I got it working, but if I don't use '->remove()' before setting a new hat, you have both on at the same time.

I know the reason behind the crash is that I'm trying to set a hat and if it's the first hat you pick, it removes a nothing hat (0 hats set, still tries removing)

I tried fixing this by doing

Code: Select all

if (MyHat != 0) {
   MyHat->remove();
   MyHat = 0;
}
But this doesn't work and it still tries removing.
So is there any way of detecting if it even CAN remove the hat, before trying to do so?
irr::Dave
Posts: 8
Joined: Wed Jul 16, 2014 4:17 pm

Re: IAnimatedSceneNode->remove() crash

Post by irr::Dave »

Hi

Do you initialize MyHat with 0?
Or do you remove the Hat elsewhere (via another variable) and don't set the above MyHat variable to 0?

Regards
LunaRebirth
Posts: 386
Joined: Sun May 11, 2014 12:13 am

Re: IAnimatedSceneNode->remove() crash

Post by LunaRebirth »

Like this:
Pseudo-Code --

Code: Select all

IAnimatedSceneNode* MyHat;
 
void setHat() {
    if (MyHat != 0) {
       MyHat->remove();
       MyHat = 0;
    }
}
int main() {
   MyHat = 0;
   setHat();
}
So yes, I do initialize it as 0
LunaRebirth
Posts: 386
Joined: Sun May 11, 2014 12:13 am

Re: IAnimatedSceneNode->remove() crash

Post by LunaRebirth »

Debugging shows crash at remove()
irr::Dave
Posts: 8
Joined: Wed Jul 16, 2014 4:17 pm

Re: IAnimatedSceneNode->remove() crash

Post by irr::Dave »

I tried the following:

Code: Select all

irr::scene::IAnimatedMeshSceneNode *node = smgr->addAnimatedMeshSceneNode(animatedMesh, NULL, -1,
     irr::core::vector3df(0,0,0), irr::core::vector3df(0,0,0), irr::core::vector3df(1.0f,1.0f,1.0f));
//node->drop();
node->remove();
when I call remove on my node there is no crash and the node is removed from the scene (at least not displayed^^).
So I inserted a node->drop() just to check and it crashed. Was just an idea, check if you drop your Hat somewhere :wink:
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: IAnimatedSceneNode->remove() crash

Post by CuteAlien »

Sorry, not enough code to really know what's going on. Your code above looks fine and is likely not the real cause of your error. Setting to 0 and checking that should be good enough (at least if you ensure the variable is initialized to 0, for example in the constructorl). You might want to check if the reference count is > 0 to ensure the stuff irr::Dave mentioned doesn't happen.
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