Fix crash if menu is deleted while menu is open (SGR #3503).
This can happen when a menu widget (e.g. Fl_Choice) is deleted in a timer callback while the menu is open (pulldown active).
This commit is contained in:
parent
7d18420956
commit
3aa32804f7
2
CHANGES
2
CHANGES
@ -3,6 +3,8 @@ CHANGES IN FLTK 1.3.5 RELEASED: ??? ?? 2018
|
||||
|
||||
Bug fixes and other improvements
|
||||
|
||||
- Make sure not to access Fl_Menu_ widgets if the widget gets
|
||||
deleted while the menu (pulldown) is open (STR #3503).
|
||||
- Fixed CMake build (fluid) on case sensitive macOS file systems.
|
||||
- Windows/OpenGL: improved pixel format detection (STR #3119).
|
||||
- Added support for MacOS 10.14 "Mojave": all drawing to windows is done
|
||||
|
||||
@ -841,6 +841,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()) {
|
||||
@ -877,7 +881,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:
|
||||
@ -894,6 +899,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;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user