On 7/15/21 8:34 PM Bill Spitzak wrote:
It is pretty easy to write callbacks that will crash if some widget
has been deleted, which is the reason the deferred deletion is provided.
I agree. This has probably been done because I experienced crashes
around FLTK 1.1.5rcN when someone (IIRC Mike) changed code to reset the
changed() flag after the callback. At that time I was only a "user" of FLTK.
However if fltk or any of it's built-in widgets crashes because a
widget was deleted by a callback then this is a bug that should be fixed.
I agree again. This is the reason why the class Fl_Wiget_Tracker was
invented (by me) - after some work of Matt who made this class possible.
The conclusion is:
(1) if user code accesses deleted widgets in a callback it's their fault
- and we should warn not to do this.
(2) No FLTK widget must access a widget after the callback w/o checking
that it hasn't been deleted - which is done by using Fl_Widget_Tracker
and testing whether the widget still exists after calling the callback.
The only reason why Fl::delete_widget() would be needed today (in FLTK
1.4) is if something mentioned above is not taken care of. I hope I
found all cases and fixed the code in 1.1.x or at least in 1.3.x (I
don't remember exactly). Hence Fl::delete_widget() should never be
necessary WRT FLTK widgets, but users might still want it if their own
code is "broken" (or hard to fix).
Note that there's one fatal drawback of using Fl::delete_widget(): if
you ever call one of the standard FLTK dialogs or own code that uses
Fl::wait() inside a callback this could lead to unexpected (pemature)
widget deletion because Fl::wait() would delete all widgets scheduled
for deletion by Fl::delete_widget().
You received this message because you are subscribed to the Google Groups "fltk.coredev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to email@example.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkcoredev/3922dbd7-b60f-9809-efc7-708620c2534f%40online.de.
[ Direct Link to Message ]