Callback segfaults when member functions are invoked.

7 views
Skip to first unread message

52mid...@gmail.com

unread,
Jan 11, 2017, 4:16:02 AM1/11/17
to fltk.general
I recently started using FLTK and am most impressed with it, especially the documentation. I've struck a bug that I can't resolve and would much appreciate some assistance. This code works:

double Yshift = -70;

void cb_yshift(Fl_Widget *) {
   
Yshift = -y_shift->value();
}

y_shift
= new Fl_Line_Dial(x,y,70,70); x += 110;
y_shift
->color(0x38697600,FL_BLACK);
y_shift
->minimum(-160); y_shift->maximum(160);
y_shift
->step(1); y_shift->value(-40);
y_shift
->when(FL_WHEN_CHANGED);
y_shift
->callback(cb_yshift);


This code segfaults:

double Ch1Shift = 0;

void cb_ch1_shift(Fl_Widget*,void*) {
   
Ch1Shift = ch1_shift->value();
}

Fl_Line_Dial *ch1_shift = new Fl_Line_Dial(x,y,40,40);
ch1_shift
->minimum(-160); ch1_shift->maximum(160);
ch1_shift
->step(1); ch1_shift->value(0);
ch1_shift
->when(FL_WHEN_CHANGED);
ch1_shift
->callback(cb_ch1_shift);

It looks functionally identical to me, so something else may have changed of which I'm unaware. Both callbacks are outside blocks and so should be static. The latter works fine when no member functions are invoked, but invoking value() causes the problem.

Any suggestions much appreciated.

Nikita Egorov

unread,
Jan 11, 2017, 4:33:55 AM1/11/17
to fltkg...@googlegroups.com

Hi,

11.01.2017 9:37, 52mid...@gmail.com wrote:
I recently started using FLTK and am most impressed with it, especially the documentation. I've struck a bug that I can't resolve and would much appreciate some assistance. This code works:

double Yshift = -70;

void cb_yshift(Fl_Widget *) {
   
Yshift = -y_shift->value();
}

y_shift
= new Fl_Line_Dial(x,y,70,70); x += 110;
y_shift
->color(0x38697600,FL_BLACK);
y_shift
->minimum(-160); y_shift->maximum(160);
y_shift
->step(1); y_shift->value(-40);
y_shift
->when(FL_WHEN_CHANGED);
y_shift
->callback(cb_yshift);


This code segfaults:

double Ch1Shift = 0;

void cb_ch1_shift(Fl_Widget*,void*) {
   
Ch1Shift = ch1_shift->value();
}

Fl_Line_Dial *ch1_shift = new Fl_Line_Dial(x,y,40,40);
I suppose your problem here : you create a new variable "ch1_shift", but callback uses some outer/global variable having the same name and not initialized. Just remove "Fl_Line_Dial *"

Nikita Egorov
Reply all
Reply to author
Forward
0 new messages