Hi, I am getting a segmentation fault in my FLTK code. It only happens on my callback function for a Fl_Choice or Fl_Menu_Button. Here is relevant code -
in the constructor of my window -
Code:whichSensor = new Fl_Menu_Button(300, 315, 180, 25, "Sensor"); whichSensor->when(FL_WHEN_RELEASE); whichSensor->callback(cb_choice); setSensorItems();Code:void GUIWindow::setSensorItems() { whichSensor->add("Bump", 0, 0, (void*)1); whichSensor->add("Wheel_Drop", 0, 0, (void*)1); whichSensor->add("Wall", 0, 0, (void*)1); whichSensor->add("Cliff_Left", 0, 0, (void*)1); whichSensor->add("Cliff_Front_Left", 0, 0, (void*)1); whichSensor->add("Cliff_Front_Right", 0, 0, (void*)1); whichSensor->add("Cliff_Right", 0, 0, (void*)1); whichSensor->add("Virtual_Wall", 0, 0, (void*)1); whichSensor->add("Low_Side_Driver", 0, 0, (void*)1); }
If I leave the cb_choice_i empty or just have a cout statement in there, everything works fine. But as soon as I try to access a member of the window class, I get a segmentation fault. I have also tried changing v in GUIWindow* w = (GUIWindow*)v; to o, but that also gave me faults. The line in cb_choice_i is just an example; ideally I want to set it to whatever item the user chooses.Code:void GUIWindow::cb_choice(Fl_Widget* o, void* v) { GUIWindow* w = (GUIWindow*)v; w->cb_choice_i(); } void GUIWindow::cb_choice_i() { robot->setCurrentSensor(BUMP); }
I have done all of my other callback functions this and they all work fine. Here is another for example -
So I don't understand why I would be getting segmentation faults for the other. My only assumption is that it has something to do with the Fl_Menu_Button, but I don't know what. This problem has been stumping me for some time now so any help at all would be greatly appreciated.Code:void GUIWindow::cb_toggleSensorStream(Fl_Widget* o, void* v) { GUIWindow* w = (GUIWindow*)v; w->cb_toggleSensorStream_i(); } void GUIWindow::cb_toggleSensorStream_i() { robot->toggleSensorStream(); }




Reply With Quote