From ad0fc9ca23717b46639d2f28a83437300499870d Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Thu, 27 Apr 2006 21:40:47 +0000 Subject: STR #1162: Fl_Menu_Button::popup was trying to access a previously deleted widget (itself). The delayed deleting mechanism in 'Fl::delete_widget' did not work in this case because the main loop is called before the callback returns. The fix implements a type of automatic pointer that will be cleared to NULL should the widget get deleted. This may not be a 'nice' solution, but it does fix the problem reliably. We could actually use this for all widget pointers and remove the delayed delete mechanism alltogether git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@5037 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl.cxx | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/Fl_Menu_Button.cxx | 5 ++++- src/Fl_Widget.cxx | 1 + 3 files changed, 52 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Fl.cxx b/src/Fl.cxx index c9dcd0a6c..72ea71414 100644 --- a/src/Fl.cxx +++ b/src/Fl.cxx @@ -1207,6 +1207,53 @@ Fl::do_widget_deletion() { num_dwidgets = 0; } +static Fl_Widget ***widget_watch = 0; +static int num_widget_watch = 0; +static int max_widget_watch = 0; + +void Fl::watch_widget_pointer(Fl_Widget *&w) +{ + Fl_Widget **wp = &w; + int i; + for (i=0; ipopup(Fl::event_x(), Fl::event_y(), label(), mvalue(), this); } else { @@ -58,7 +60,8 @@ const Fl_Menu_Item* Fl_Menu_Button::popup() { } picked(m); pressed_menu_button_ = 0; - redraw(); + if (mb) mb->redraw(); + Fl::release_widget_pointer(mb); return m; } diff --git a/src/Fl_Widget.cxx b/src/Fl_Widget.cxx index 3c637767b..9f33b2cf3 100644 --- a/src/Fl_Widget.cxx +++ b/src/Fl_Widget.cxx @@ -133,6 +133,7 @@ extern void fl_throw_focus(Fl_Widget*); // in Fl_x.cxx // However, it is only legal to destroy a "root" such as an Fl_Window, // and automatic destructors may be called. Fl_Widget::~Fl_Widget() { + Fl::clear_widget_pointer(this); if (flags() & COPIED_LABEL) free((void *)(label_.value)); parent_ = 0; // Don't throw focus to a parent widget. fl_throw_focus(this); -- cgit v1.2.3