void MainMenu::cb_userinput(fltk::Input *in, void *v)
{
MainMenu *mm = (MainMenu*)v;
memset(user_input, '\0', sizeof(user_input));
strcpy((char*)user_input, in->value());
in->value('\0');
memset(user_input, '\0', sizeof(user_input));
mm->ExitFromMenu();
}
void MainMenu::ExitFromMenu()
{
Menu->clear();
Menu->end();
}
the line I am calling callback
input->callback((fltk::Callback*)cb_userinput, this);
callback function is called successfully, if I remove both the lines from below function, then my program runs successfully but if I use both of these lines then program gives segmentation fault error,
void MainMenu::ExitFromMenu()
{
//Menu->clear();
//Menu->end();
}
I can't use gdb as this program is running on remote device, can anyone help me to find out the issue? thanks in advance.
Full class
class MainMenu : public IUserOptions
{
protected:
Group *Menu;
void DisplayUserOptions();
static char user_input[3];
static void cb_userinput(fltk::Input *in, void *v);
int user_choice;
void ExitFromMenu();
public:
MainMenu(vector<string> userChoices);
int GetUserOption();
~MainMenu();
};
char MainMenu::user_input[3];
MainMenu::MainMenu(vector<string> userChoices) : IUserOptions(userChoices)
{
Menu = new fltk::Group(0, 0, 320, 220, "");
}
void MainMenu::cb_userinput(fltk::Input *in, void *v)
{
MainMenu *mm = (MainMenu*)v;
memset(user_input, '\0', sizeof(user_input));
strcpy((char*)user_input, in->value());
in->value('\0');
memset(user_input, '\0', sizeof(user_input));
mm->ExitFromMenu();
}
void MainMenu::ExitFromMenu()
{
Menu->clear();
Menu->end();
}
void MainMenu::DisplayUserOptions()
{
Menu->set_vertical();
Menu->begin();
fltk::Widget *Wel = new fltk::Widget(0, 0,320, 220, "");
Wel->color((fltk::Color)0xf5751000);
Wel->box(fltk::FLAT_BOX);
fltk::Widget *MAIN_MENU_BOX = new Widget(0, 0, 320, 30, "Genus Power Vers 1.0.0");
MAIN_MENU_BOX->box(FLAT_BOX);
MAIN_MENU_BOX->color((fltk::Color)0x6E040600);
MAIN_MENU_BOX->labelfont(fltk::TIMES_BOLD);
MAIN_MENU_BOX->labelsize(20);
MAIN_MENU_BOX->labelcolor(WHITE);
// first Menu Option Download Meter
fltk::Button *mb1= new fltk::Button(10,40,200,30, " 1. Download ");//60
mb1->labelfont(fltk::TIMES_BOLD);
mb1->labelsize(16);
mb1->argument(1);
mb1->take_focus();
mb1->color((fltk::Color)0x6E040600);
mb1->align(fltk::ALIGN_CENTER);
mb1->labelcolor(WHITE);
mb1->box(ROUNDED_BOX);
fltk::Input* input = new fltk::Input(400, 60, 120, 25, "key :");
input->labelsize(14);
input->callback((fltk::Callback*)cb_userinput, this);
input->take_focus();
input->argument(2);
input->labelfont(HELVETICA_BOLD_ITALIC);
input->textsize(14);
input->textfont(fltk::COURIER_BOLD);
input->when(fltk::WHEN_ENTER_KEY_CHANGED);
// Second Menu Option to Print
fltk::Button *mb2= new fltk::Button(10,80,200,30, " 0. Quit ");//60
mb2->labelfont(fltk::TIMES_BOLD);
mb2->labelsize(16);
mb2->color((fltk::Color)0x6E040600);
mb2->align(fltk::ALIGN_CENTER);
mb2->labelcolor(WHITE);
mb2->box(ROUNDED_BOX);
Menu->end();
}
int MainMenu::GetUserOption()
{
cout << endl << "Address of this:" << this << endl;
getchar();
DisplayUserOptions();
return user_choice;
}
MainMenu::~MainMenu()
{
delete Menu;
}
and my base class is
class IUserOptions
{
protected:
vector<string> UserChoices;
public:
IUserOptions(vector<string> userChoices);
virtual int GetUserOption() = 0;
virtual ~IUserOptions();
};