David Lopez wrote:
> Hi, I am migrating an application from FLTK 1.1.3 to FLTK 1.1.9.
> The problem is the following
> I have a button whose callback deletes the button itself.
> 
> It works fine in 1.1.3, since the code for Fl_Widget::do_callback is the 
> following:
>       void do_callback() {callback_(this,user_data_);}
> 
> But in 1.1.9 that code changed to:
>       void do_callback() {callback_(this,user_data_); if (callback_ != 
> default_callback) clear_changed();}
> 
> So, the instruction clear_changed() executes after the object was destroyed, 
> causing a crash.
> 
> The question is, isn't valid to delete a widget in its callback?
> In such case, what would you suggest doing?

        You probably want Fl::delete_widget(). See notes on this page:
        http://fltk.org/documentation.php/doc-1.1/Fl.html#Fl.delete_widget

* * *
void delete_widget(Fl_Widget*);

Schedules a widget for deletion at the next call to the event loop.
Use this method to delete a widget inside a callback function.
As with normal widget deletion it is your responsibility to remove()
the widget from any parent group or window before calling this.

To avoid early deletion of widgets, this function should be called
toward the end of a callback and only after any call to the event loop
(Fl::wait(), Fl::flush(), Fl::check(), fl_ask(), etc.).
* * *

        I believe in later releases (1.3.x and up, not relevant in
        your cases), the call to remove() is no longer required.
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to