ofNode - Strange Crash Problem[Solve]


#1

I made a very simple class to test ofNode.But i met a strange crash problem~


class MyNodeClass{
public:
ofNode nodeA,nodeB;

MyNodeClass(){
    nodeA.setPosition(ofVec3f(0,0,0));
    nodeB.setPosition(ofVec3f(0,100,0));
    nodeB.setParent(nodeA);
}

void draw(){
    nodeA.draw();
    nodeB.draw();
}
};


 // in ofApp:--------------------------------------------------------------
    void ofApp::setup(){

  }

 //--------------------------------------------------------------
  void ofApp::update(){

}

//--------------------------------------------------------------
   void ofApp::draw(){
       ofBackground(0);
       cam.begin();
      myNode.draw();
       cam.end();
    }

   //--------------------------------------------------------------
   void ofApp::keyPressed(int key){
      myNode = MyNodeClass();
   }

When i run the program.Everything is fine until i pressed the keyboard.

It shows the problem in “children”. Did i missed something?

Environment:Xcode9 - OF0.98 - macOs Mojave


#2

This is a known problem in 0.9.8 where a node with children would try to notify them of it’s destruction after the children themselves where destroyed. This is solved in 0.10 but if you don’t want to upgrade probably switching the order of declaration of the nodes in the .h or manually removing the parenting before destruction will solve the issue


#3

Thanks,arturo ! I replaced the for loop by

while (!children.empty()){

(*children.begin())->clearParent();

}

It solved that problem~