RE: [fltk.general] Callback segfaults when member functions are invoked. [General Use]

7 views
Skip to first unread message

MacArthur, Ian (Leonardo, UK)

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

OK, I concur with Nikita's suggestion here...


The "ch1_shift" in this code here:

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


Is not the same "ch1_shift" that is in this code below, since this one is declared after the one above is used in the callback, and so presumably is not in scope for the callback.
The one above is probably referring to some other variable called "ch1_shift", which I guess is NULL at the point that the callback executes it.

> Fl_Line_Dial *ch1_shift = new Fl_Line_Dial(x,y,40,40);




> 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.

No, as noted, I suspect that the variable scope is different and hence the function of the code is altered, producing the segfault you report.




Leonardo MW Ltd
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 3EL
A company registered in England & Wales. Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************

52mid...@gmail.com

unread,
Jan 11, 2017, 11:10:35 AM1/11/17
to fltk.general, ian.ma...@leonardocompany.com
YES! Thanks, Nikita - removing the "Fl_Line_Dial *" DID do the trick! I'll need a bit of pondering to get the reasons clear in my mind, though.

And BTW congratulations to the FLTK team for a superb piece of kit. A real pleasure to learn and use.

52mid...@gmail.com

unread,
Jan 11, 2017, 11:10:35 AM1/11/17
to fltk.general, ian.ma...@leonardocompany.com
Thanks to both for the detailed reply, and sorry about the dual post - only just joined the group. I understand what you're saying and will examine it.

Most of my coding for the past decade has been Perl with some assembler. Segfaults don't exist in Perl (that I can recall) and microcontrollers don't even know what segments are, so I've zero experience in debugging this sort of thing.

I'll post back after getting my head around it.
Reply all
Reply to author
Forward
0 new messages