summaryrefslogtreecommitdiff
path: root/src/Fl_Menu.cxx
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2018-12-07 14:45:50 +0100
committerAlbrecht Schlosser <albrechts.fltk@online.de>2018-12-07 14:45:50 +0100
commitd87ac9b59783dec5628e7ae242b390cf5097b77a (patch)
tree3083faa2948257aa675f78aacd6ff95462bc5859 /src/Fl_Menu.cxx
parentf9228e55b3dbe90b08691d16e10c252eeb6c3257 (diff)
Fix crash if menu is deleted while menu is open (SGR #3503).
This can happen if a menu widget (e.g. Fl_Choice) is deleted in a timer callback while the menu is open (pulldown active).
Diffstat (limited to 'src/Fl_Menu.cxx')
-rw-r--r--src/Fl_Menu.cxx9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/Fl_Menu.cxx b/src/Fl_Menu.cxx
index 1d7f47672..b3e1f5c65 100644
--- a/src/Fl_Menu.cxx
+++ b/src/Fl_Menu.cxx
@@ -867,6 +867,10 @@ const Fl_Menu_Item* Fl_Menu_Item::pulldown(
int menubar) const {
Fl_Group::current(0); // fix possible user error...
+ // track the Fl_Menu_ widget to make sure we notice if it gets
+ // deleted while the menu is open (STR #3503)
+ Fl_Widget_Tracker wp((Fl_Widget *)pbutton);
+
button = pbutton;
if (pbutton && pbutton->window()) {
for (Fl_Window* w = pbutton->window(); w; w = w->window()) {
@@ -903,7 +907,8 @@ const Fl_Menu_Item* Fl_Menu_Item::pulldown(
initial_item = pp.current_item;
if (initial_item) goto STARTUP;
- // the main loop, runs until p.state goes to DONE_STATE:
+ // the main loop: runs until p.state goes to DONE_STATE or the menu
+ // widget is deleted (e.g. from a timer callback, see STR #3503):
for (;;) {
// make sure all the menus are shown:
@@ -920,6 +925,8 @@ const Fl_Menu_Item* Fl_Menu_Item::pulldown(
{
const Fl_Menu_Item* oldi = pp.current_item;
Fl::wait();
+ if (wp.deleted()) // menu widget has been deleted (STR #3503)
+ break;
if (pp.state == DONE_STATE) break; // done.
if (pp.current_item == oldi) continue;
}