Ticket #15221 (closed defect: fixed)
Unrealised widgets being used to handle gtk signals
|Reported by:||Chuddah||Owned by:|
|Keywords:||WIDGET_REALIZED_FOR_EVENT Gtk-CRITICAL MenuBar Menu||Cc:|
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.