After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 82366 - button click / popup event race
button click / popup event race
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: Other
2.0.x
Other All
: Normal major
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks: 78764
 
 
Reported: 2002-05-20 15:25 UTC by Michael Meeks
Modified: 2011-02-04 16:09 UTC
See Also:
GNOME target: ---
GNOME version: 2.0



Description Michael Meeks 2002-05-20 15:25:42 UTC
With this code, I can reliably get the:

(lt-test-ui:17237): Gtk-CRITICAL **: file gtkwidget.c: line 2933
(gtk_widget_event): assertion `WIDGET_REALIZED_FOR_EVENT (widget, event)'
failed

warning. I suspect this is a pre-cursor to a crasher bug we see in nautilus
- presumably a similar gtk+ race condition #78764.

My test code is this [ I've no idea if nautilus does significant work in
map_event - I doubt it ]:


static gboolean
button_press_event_cb (GtkWidget      *widget,
		       GdkEventButton *event,
		       gpointer        user_data)
{
	GtkMenu *menu = user_data;

	if (event->button == 3) {
		gtk_menu_popup (
			menu, NULL, NULL, NULL,
			NULL, 0, event ? event->time : GDK_CURRENT_TIME);
		/* do some popup action ... */
	}

	return TRUE;
}

static void
delay_cb (void)
{
	g_warning ("Delay Callback");
	sleep (4);
}

static void
do_reparent_test (void)
{
	GtkWidget *menu;
	GtkWidget *item;
	GtkWidget *ebox;
	GtkWidget *window;
	
	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_window_set_default_size (GTK_WINDOW (window), 1024, 768);
	ebox = gtk_event_box_new ();
	gtk_container_add (GTK_CONTAINER (window), ebox);
	gtk_widget_show_all (window);

	menu = gtk_menu_new ();
	gtk_widget_show (menu);

	item = gtk_menu_item_new_with_label ("foo");
	gtk_widget_show (item);
	gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);

	item = gtk_menu_item_new_with_label ("baa");
	gtk_widget_show (item);
	gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);


	g_signal_connect (ebox, "button_press_event",
			  G_CALLBACK (button_press_event_cb), menu);

	g_signal_connect (window, "map_event",
			  G_CALLBACK (delay_cb), NULL);

	gtk_main ();
}
Comment 1 Michael Meeks 2002-05-20 15:33:51 UTC
Meant to say, you need to do a load of right clicks on the window
while it's blocking to get the effect.
Comment 2 Michael Meeks 2002-05-30 12:14:55 UTC
Ok; so the reason why this debug is churning is most likely not the
cause of my problem - which seems to be a GtkMenu being finalized
without being unrealized - down to some odd interaction with
GtkOptionMenu and whacking new children into it etc.

So - it seems, this is to do with the GtkMenu 'transfer_window' it
seems that unrealized GtkMenus can get events on their
transfer_window, hence the warning.
Comment 3 Michael Meeks 2002-05-30 16:11:18 UTC
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtk+/ChangeLog,v
retrieving revision 1.3338.2.77
diff -u -p -u -r1.3338.2.77 ChangeLog
--- ChangeLog	30 May 2002 09:41:41 -0000	1.3338.2.77
+++ ChangeLog	30 May 2002 15:57:36 -0000
@@ -1,3 +1,10 @@
+2002-05-30  Michael Meeks  <michael@ximian.com>
+
+
* gtk/gtkmenu.c (gtk_menu_popup): destroy the transfer
+
window if the grab fails so we don't get events on this
+
window after the menu is finalized with a duff GtkWidget
+
pointer: #82366
+
 Mon May 28 13:28:10  Shivram U  <shivaram.upadhyayula@wipro.com>
 
 	* gtk/gtktextbuffer.c (selection_data_get_buffer): Check if the owner
Index: gtk/gtkmenu.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkmenu.c,v
retrieving revision 1.97.2.3
diff -u -p -u -r1.97.2.3 gtkmenu.c
--- gtk/gtkmenu.c	30 May 2002 05:12:30 -0000	1.97.2.3
+++ gtk/gtkmenu.c	30 May 2002 15:57:38 -0000
@@ -713,6 +713,7 @@ gtk_menu_popup (GtkMenu		    *menu,
        * try again.
        */
       menu_shell->parent_menu_shell = NULL;
+      menu_grab_transfer_window_destroy (menu);
       return;
     }
 
Comment 4 Michael Meeks 2002-05-31 16:43:27 UTC
Tim approved this, so I've committed to both branches, I hope that's ok.

There can be no other problems of this kind, since we realize shortly
after this, and the unrealize cleans up properly.