Opened 2 years ago

Last modified 15 months ago

#14292 reopened defect

GLIB warnings on Ubuntu 12.04 when destroying wxMenuBar

Reported by: eran Owned by:
Priority: normal Milestone:
Component: wxGTK Version: stable-latest
Keywords: Cc: anatoli.steinmark@…
Blocked By: Blocking:
Patch: yes

Description

Testing wxWidgets's minimal sample on Ubuntu 12.04 (Precise) on exit it spams these warnings to the terminal:

(minimal:8605): LIBDBUSMENU-GLIB-WARNING **: Trying to remove a child that doesn't believe we're it's parent.

After debugging it, its seems that that these warnings are coming from

wxWindow::~wxWindow (this=0x748b00, __in_chrg=<optimized out>) at ../src/gtk/window.cpp:2351

Here is the complete thread on the wx-users mailing list I had with VZ
https://groups.google.com/d/topic/wx-users/9rprajn67Gg/discussion

Attached is a patch that fixes this problem.

Attachments (3)

gtk-menu.patch download (1.1 KB) - added by eran 2 years ago.
gtk-menu.patch
backtrace.txt download (7.5 KB) - added by kyuu 22 months ago.
minimal.cpp.patch download (2.6 KB) - added by kyuu 21 months ago.

Download all attachments as: .zip

Change History (26)

Changed 2 years ago by eran

gtk-menu.patch

comment:1 Changed 2 years ago by Hanmac

  • Status changed from new to confirmed

i can confim this error, and i want to say thank you that you want to fix this.

comment:2 Changed 2 years ago by vadz

  • Cc pcor added
  • Summary changed from GLIB warnings on Ubuntu 12.04 to GLIB warnings on Ubuntu 12.04 when destroying wxMenuBar

Paul, if you could please confirm that it's really not necessary to gtk_widget_destroy() GtkMenus it would be perfect. TIA!

comment:3 Changed 2 years ago by pcor

  • Cc pcor removed

The patch is not really correct, deleting a wxMenuBar won't destroy it's m_widget (although the one attached to the frame will be destroyed when the frame is destroyed). I strongly suspect this is yet another bug in Ubuntu, and I would prefer to find a way to restrict this "fix" to Ubuntu only.

comment:4 Changed 23 months ago by vadz

Unfortunately it becomes very clear that I won't be able to do anything about this if we want to do 2.9.4 any time soon. So the question is whether it's better to do nothing and leave with the warnings in 2.9.4 or apply the patch and hope to find a better solution later?

comment:5 Changed 23 months ago by PC

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

(In [71648]) Workaround for Ubuntu 12.04 run time warning
"LIBDBUSMENU-GLIB-WARNING : Trying to remove a child that doesn't believe we're it's parent."
Avoid calling gtk_widget_destroy() on a wxMenuBar attached to a frame
Fixes #14292

comment:6 follow-up: Changed 22 months ago by kyuu

  • Resolution fixed deleted
  • Status changed from closed to reopened

Is this really have been fixed? In my application I'm dynamically creating and removing menus in the menubar and get segmentation faults because of this in Ubuntu 12.04 wxGTK. I can provide a backtrace if needed. This is really annoying.

comment:7 in reply to: ↑ 6 Changed 22 months ago by kyuu

Replying to kyuu:

Is this really have been fixed? In my application I'm dynamically creating and removing menus in the menubar and get segmentation faults because of this in Ubuntu 12.04 wxGTK. I can provide a backtrace if needed. This is really annoying.

Tested in revision 71965, BTW.

comment:8 Changed 22 months ago by kyuu

  • Cc anatoli.steinmark@… added

comment:9 Changed 22 months ago by vadz

  • Milestone 2.9.4 deleted

The original bug was seen in the minimal sample that doesn't modify the menus dynamically so I think that it was indeed fixed. But apparently it was not the only bug introduced in GTK by our Ubuntu friends.

Anyhow, backtrace could be useful but most useful would be the simplest possible way to reproduce the problem, could you please make a patch to the minimal sample showing it? Or perhaps it can be already seen in the menu sample which has commands for manipulating the menus? If so, what is the exact sequence of actions needed to trigger it?

comment:10 Changed 22 months ago by kyuu

Yes, it can be already seen in the menu sample, just do the sequence: Ctrl+A -> Ctrl+D, which adds a menu and deletes it afterwards. Every time the menu is deleted, you get:

(menu:2382): LIBDBUSMENU-GTK-CRITICAL : watch_submenu: assertion `GTK_IS_MENU_SHELL(menu)' failed

(menu:2382): LIBDBUSMENU-GLIB-WARNING : Trying to remove a child that doesn't believe we're it's parent.

In my application, every time a file is opened, the menu bar is updated to include the correct set of menus, which implicates removing old menus and inserting new menus. Whenever a menu is removed (it doesn't matter if I'm using wxMenuBar::Replace() or wxMenuBar::Remove()) I see the above messages. Multiple files can also be opened, in which case the procedure for one file is done in a loop for each of the selected files. If more than two files are opened this way I get a segmentation fault (see attached backtrace).

Sometimes I also get the following messages:

(developer:2301): GLib-GObject-CRITICAL : g_signal_handlers_disconnect_matched: assertion `G_TYPE_CHECK_INSTANCE (instance)' failed

(developer:2301): GLib-GObject-WARNING : instance of invalid non-instantiatable type `(null)'

The problem seems to be in the removal of menus, since the messages only show up when a menu is removed, plus, if I comment out the menubar update code, I get no such messages and no segmentation faults.

I'm sorry, but this is all the information I can give you on this matter. I don't know how to reproduce the segmentation fault in the menu sample. If there is a need, I can provide the source code of my application.

Just as I was writing this, the update manager popped up with updates also inclusing libdbus, so I installed the updates, rebuilt wxWidgets and my application in order to see if the updates would fix the problem, but to no avail.

comment:11 follow-up: Changed 22 months ago by vadz

Looks like this is related to wxYield() call in clipboard code. Can it be reproduced if you stub out the CanPaste() call (i.e. always return true from it)?

But it would be actually more useful to have the backtrace for the menu sample rather than for your own code (which we don't have/know). Could you please attach it as well?

comment:12 in reply to: ↑ 11 Changed 22 months ago by kyuu

Replying to vadz:

Looks like this is related to wxYield() call in clipboard code. Can it be reproduced if you stub out the CanPaste() call (i.e. always return true from it)?

I changed my code, so it always returns true, instead of calling CanPaste(), but the segfault still persists and can be reproduced (in my code). The only effect of this change was that the backtrace only contains calls to GTK and wxWidgets functions.

But it would be actually more useful to have the backtrace for the menu sample rather than for your own code (which we don't have/know). Could you please attach it as well?

I can't reproduce the segfault in the menu sample. I will try to investigate it further. I have the feeling it has to do with 'update UI' event processing.

Changed 22 months ago by kyuu

comment:13 Changed 22 months ago by kyuu

  • Resolution set to invalid
  • Status changed from reopened to closed

Ok, after a long debugging session I still wasn't able to narrow down the source of the segfault. Then I noticed a strange behavior of the global menubar: After inserting a menu, the menus to the left of the insertion position suddenly appeared in reverse order. You can see this behavior in the menu sample as well: Press Ctrl+I, move the mouse cursor over the global menubar and you should see a reversed order of appearance for the first three menus. After switching to a different window and switching back to the menu sample window, the order of appearance is restored.

So I followed this article: http://www.howtogeek.com/106009/disable-the-global-menu-appmenu-in-ubuntu-11.04-and-11.10/ and removed the global menubar and suddenly the segfault didn't occur anymore. I was still getting a GTK warning, so I went a step further and installed gnome classic following this article: http://www.howtogeek.com/105911/how-to-install-the-classic-gnome-desktop-in-ubuntu-11.10/ and now even the warnings are gone.

It seems after all this is a problem with Ubuntu Unity and not wxWidgets.

comment:14 Changed 22 months ago by vadz

  • Resolution invalid deleted
  • Status changed from closed to reopened

As much as I'd like to avoid dealing with Ubuntu custom GTK modifications, I'm afraid we can't do this and need to find a way to deal with the problem without forcing all the users to disable the global menu. Especially as it seems that everybody else is going to follow Ubuntu in this craziness anyhow :-(

comment:15 follow-up: Changed 21 months ago by kyuu

I see, but at least there is a way around this problem, even if it means to tell the user to disable the global menu. When I get more time I will try again to reproduce the segfault in one of the samples.

comment:16 in reply to: ↑ 15 Changed 21 months ago by vadz

Replying to kyuu:

When I get more time I will try again to reproduce the segfault in one of the samples.

This would be really, really helpful. TIA!

comment:17 follow-up: Changed 21 months ago by kyuu

Ok, I was finally able to reproduce the segfault in the minimal sample.

Apply the attached patch, run the minimal sample, click on the button and you should receive a segfault. Two factors are important to reproduce the segfault:

  1. The menu item must have an accelerator. Without an accelerator, there will be only the already mentioned warnings, but no segfault.
  1. The recreation (removal, plus insertion) of the menu must be done very quickly. In the patched minimal sample the menu is recreated in a loop and for any number of iterations greater than two, you will receive the segfault.

Changed 21 months ago by kyuu

comment:18 Changed 21 months ago by Darr247

Running Ubuntu 12.04, using GNOME (3), not Unity and not GNOME Classic.

I hate GlobalMenu and turn it off (remove it) whenever I see it, even removing firefox's plugin.

But running BOINC 7.0.27 from Ubuntu's regular repos,
Just opening the GUI manager to monitor the client service, I'm seeing

$ boincmgr

(boincmgr:3075): LIBDBUSMENU-GLIB-WARNING : Trying to remove a child that doesn't believe we're it's parent.
(boincmgr:3075): LIBDBUSMENU-GLIB-WARNING
: Trying to remove a child that doesn't believe we're it's parent.
(boincmgr:3075): LIBDBUSMENU-GLIB-WARNING : Trying to remove a child that doesn't believe we're it's parent.
(boincmgr:3075): LIBDBUSMENU-GLIB-WARNING
: Trying to remove a child that doesn't believe we're it's parent.
(boincmgr:3075): LIBDBUSMENU-GLIB-WARNING : Trying to remove a child that doesn't believe we're it's parent.
(boincmgr:3075): LIBDBUSMENU-GLIB-WARNING
: Trying to remove a child that doesn't believe we're it's parent.
(boincmgr:3075): Gdk-CRITICAL : IAgdk_gc_set_foreground: assertion `color != NULL' failed

You could also correct the error message to use the possessive instead of a contraction.

e.g. "Trying to remove a child that doesn't believe we're its parent."

Thanks.

comment:19 Changed 19 months ago by JCMS

A fix for wxPython would be really nice too. Thanks

comment:20 Changed 16 months ago by PC

(In [73276]) Better fix for avoiding warnings from Ubuntu libdbusmenu

Previous workaround from r71648, modified in r72560, broke MDI child menu handling
See #14292

comment:21 Changed 16 months ago by PC

(In [73277]) Use proper reference counting on GtkMenuItem that we keep a pointer to

Fixes crash that occurs with Ubuntu libdbusmenu
See #14292

comment:22 in reply to: ↑ 17 Changed 16 months ago by pcor

Replying to kyuu:

Ok, I was finally able to reproduce the segfault in the minimal sample.

After r73277, the sample still spits out some warnings, but no longer crashes.

comment:23 Changed 15 months ago by PC

(In [73357]) backport of r73276, fix for libdbusmenu warnings, see #14292

Note: See TracTickets for help on using tickets.