node->remove() SegFault, what the hell ?!

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
moktar
Posts: 4
Joined: Thu Feb 20, 2014 8:20 pm

node->remove() SegFault, what the hell ?!

Post by moktar »

Hi !

Firstly, scuse me for my english speaking, i'm french.

For my last bachelor year, i've to create a small video game using irrlicht . But i've a problem .

Steps :

1) i create a node, i set his position, and i push him in a vector wich is stored in a class .

2) i need to delete some nodes in this vector : myVec->remove(); but the compiler said " WHAT THE gently caress ARE U DOING ???? segFault"

I really need your help because i don't know how to delete these nodes . I've thought about a solution that use sceneManager->clear(), but draw all the scene isn't a good solution ...

Some code : ( if the node and the nodeList are at the same place, delete nodeList)

Code: Select all

 
bool CollisionManager::collisionWithBubble(ISceneNode *node, vector<ISceneNode*> nodeList, Game &game){
 
    if(node){   
        for(int i=0; i<nodeList.size(); ++i){
 
            if(node->getPosition()==nodeList[i]->getPosition()){
            
                cout<<"X "<<nodeList[i]->getPosition().X/3<<"Y "<<nodeList[i]->getPosition().Y/3<<endl;
                
                if(game.bubbleList[3-nodeList[i]->getPosition().Y/3][nodeList[i]->getPosition().X/3].getLvl()==3)
                    nodeList[i]->remove();
                
                game.bubbleList[3-nodeList[i]->getPosition().Y/3][nodeList[i]->getPosition().X/3].up();             
                return true;
            }
 
        }
    }
    return false;
}
 
code ( where the nodeList is created ) this is in another function

Code: Select all

 
 
for(int i=0; i<4; i++){
 
        for(int j=0; j<4; j++){
            
            if(tempo[i][j].getId()!=-1){            
                                                
                scene::ISceneNode * node2 = node->clone(); 
                node2->setVisible(true); 
                if (node2){
 
                                        
                    node2->setPosition(core::vector3df(tempo[i][j].getX()*3,tempo[i][j].getY()*3,-1));          
                    if(tempo[i][j].getLvl()>0){             
                    node2->setScale(core::vector3df(tempo[i][j].getLvl()*0.5,tempo[i][j].getLvl()*0.5,tempo[i][j].getLvl()*0.5));
                    }
                    else
                    node2->setScale(core::vector3df(0.25,0.25,0.25));
                    /*node2->addAnimator(anim);
                            anim->drop();*/
                    }
                
                nodeList.push_back(node2);
            }
        }
    }
 
 
thanking you for your answers !!

P. Titouan
CERI Avignon
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: node->remove() SegFault, what the hell ?!

Post by CuteAlien »

Seeing that you remove the node but don't remove it from the list itself - maybe you try to remove it twice? Otherwise really can't tell much without having the full code to reproduce it. Use the debugger and check where it crashes - that's what debuggers are there for.
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
zerochen
Posts: 273
Joined: Wed Jan 07, 2009 1:17 am
Location: Germany

Re: node->remove() SegFault, what the hell ?!

Post by zerochen »

hi,

2 hints:

1) after you remove the node you try to access the node s position. that would lead to a crash.
2) you are copying the nodeList. so editing the nodeList in a function still doesnt change the original nodeList

regards
zerochen
moktar
Posts: 4
Joined: Thu Feb 20, 2014 8:20 pm

Re: node->remove() SegFault, what the hell ?!

Post by moktar »

Thank you,

I will use the debbuger, i think, i try to use the node after removing him !

Have a nice day,
Post Reply