Opened 7 years ago

Closed 7 years ago

#15221 closed defect (fixed)

Unrealised widgets being used to handle gtk signals

Reported by: Chuddah Owned by:
Priority: critical Milestone: 2.9.5
Component: wxGTK Version: stable-latest
Blocked By: Blocking:
Patch: yes


Firstly, I think this is more of a GTK bug but the patch here prevents this bug from propagating up to wxWidgets

It is possible to get GTK into a state of trying to handle signals using widgets that have been previously unrealized.

When a menubar has been "activated" (a menu shown) the menubar and the shown menu gets placed on the GTK window_group->grabs list via a call to gtk_grab_add().
When a menu item is selected or the menu gets dismissed these widgets gets removed from this list (internally handled by GTK signals) via calls to gtk_grab_remove().

These grabs get first pick at handling gtk signals [gtkmain.c: gtk_main_do_event()].
Before acting on the signal GTK checks to see if the widget is realized; if this test fails then the signal is not handled and a warning is printed
Gtk-CRITICAL : IAgtk_widget_event: assertion `WIDGET_REALIZED_FOR_EVENT (widget, event)' failed

If a widget is ever in the window_group->grabs list that is not realized then each signal that comes through to GTK prints the above error\warning and dismisses the signal handling: this leaves the application completely unresponsive.

To get GTK in this state from wxWidgets an application simply has to call wxFrame::SetMenuBar(), while the menu is 'activated', with a new menu_bar.


  • User opens a menu bar menu *


This happens because the first menu bar is detached causes GTK to unrealize the widget but doesnt remove the menu bar nor the shown menus from the grabs list.

Ive added a wxPython script which allows for easy reproduction.

The patch Ive added calls gtk_widget_hide() and gtk_grab_remove() for the menubar and each menu when detaching a menubar from a frame.


Attachments (2) download (1.9 KB) - added by Chuddah 7 years ago.
wxPython script to help reproduce this bug
release_menu_grab_event_handlers.cpp.diff download (685 bytes) - added by Chuddah 7 years ago.
patch file

Download all attachments as: .zip

Change History (4)

Changed 7 years ago by Chuddah

wxPython script to help reproduce this bug

Changed 7 years ago by Chuddah

patch file

comment:1 Changed 7 years ago by vadz

This looks like a GTK+ bug to me, to be honest: why do they allow hiding a widget that has the focus grab? But I'll apply your fix/workaround even so, I agree that it's important to avoid this.

Thanks for finding and fixing this problem!

comment:2 Changed 7 years ago by VZ

  • Resolution set to fixed
  • Status changed from new to closed

(In [74056]) Ensure that detached menus don't keep focus grab in wxGTK.

A widget being hidden must remove its focus grab with GTK+, otherwise GTK+
would continue sending all input messages to it but fail to process them
because the widget is not realized any more, resulting in a complete freeze of
the entire program.

Do it when detaching menus from menubar and menubar from the frame to fix just
such a problem in case SetMenuBar() was called while the previous menubar was

Closes #15221.

Note: See TracTickets for help on using tickets.