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 704600 - Cannot add items to menu hierarchy - assertion `GLADE_IS_WIDGET_ADAPTOR (adaptor)' failed
Cannot add items to menu hierarchy - assertion `GLADE_IS_WIDGET_ADAPTOR (adap...
Status: RESOLVED FIXED
Product: glade
Classification: Applications
Component: general
3.8.x
Other All
: Normal major
: ---
Assigned To: Glade 3 Maintainers
Glade 3 Maintainers
: 670764 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2013-07-20 10:10 UTC by Nick Dowell
Modified: 2016-05-19 00:11 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Fix for reported issue (1.44 KB, patch)
2013-08-11 17:43 UTC, Nick Dowell
none Details | Review

Description Nick Dowell 2013-07-20 10:10:11 UTC
Issue found with glade 3.8.3, gtk+-2.0 2.24.11 (on Mac OS X 10.8.4, installed using homebrew)


Steps to reproduce:

1. Create a new project
2. Add a window and menu bar
3. Edit the menu bar
4. Switch to the 'Hierarchy' tab
5. Press the '+ Add' button


Outcome:

Nothing happens in the UI, but an error message is shown on the console:

(glade-3:45951): GladeUI-CRITICAL **: GladeWidget *glade_command_create(GladeWidgetAdaptor *, GladeWidget *, GladePlaceholder *, GladeProject *): assertion `GLADE_IS_WIDGET_ADAPTOR (adaptor)' failed


Trying to add an item using the context menu ("Add child ... item") also fails, but silently.

As such it is not possible to edit menus.



Running under gdb with --g-fatal-warnings gives the following backtrace:


Program received signal SIGTRAP, Trace/breakpoint trap.
0x000000010094cfa6 in g_logv ()
(gdb) bt
  • #0 g_logv
  • #1 g_log
  • #2 glade_command_create
  • #3 glade_gtk_menu_shell_build_child
  • #4 glade_marshal_OBJECT__OBJECT_UINT
  • #5 g_closure_invoke
  • #6 signal_emit_unlocked_R
  • #7 g_signal_emit_valist
  • #8 g_signal_emit
  • #9 glade_base_editor_add_child
  • #10 _g_closure_invoke_va
  • #11 g_signal_emit_valist
  • #12 g_signal_emit
  • #13 gtk_real_button_released
  • #14 _g_closure_invoke_va
  • #15 g_signal_emit_valist
  • #16 g_signal_emit
  • #17 gtk_button_button_release
  • #18 _gtk_marshal_BOOLEAN__BOXED
  • #19 g_closure_invoke
  • #20 signal_emit_unlocked_R
  • #21 g_signal_emit_valist
  • #22 g_signal_emit
  • #23 gtk_widget_event_internal
  • #24 gtk_propagate_event
  • #25 gtk_main_do_event
  • #26 gdk_event_dispatch
  • #27 g_main_context_dispatch
  • #28 g_main_context_iterate
  • #29 g_main_loop_run
  • #30 gtk_main
  • #31 main

Comment 1 Nick Dowell 2013-07-20 11:40:47 UTC
Here's a better backtrace:

  • #0 g_logv
  • #1 g_log
  • #2 glade_command_create
    at glade-command.c line 1726
  • #3 glade_gtk_menu_shell_build_child
    at glade-gtk.c line 6689
  • #4 glade_marshal_OBJECT__OBJECT_UINT
    at glade-marshallers.c line 413
  • #5 g_closure_invoke
  • #6 signal_emit_unlocked_R
  • #7 g_signal_emit_valist
  • #8 g_signal_emit
  • #9 glade_base_editor_delegate_build_child
    at glade-base-editor.c line 327
  • #10 glade_base_editor_add_child
    at glade-base-editor.c line 718
  • #11 glade_base_editor_add_activate
    at glade-base-editor.c line 905
  • #12 _g_closure_invoke_va
  • #13 g_signal_emit_valist
  • #14 g_signal_emit
  • #15 gtk_real_button_released
  • #16 _g_closure_invoke_va
  • #17 g_signal_emit_valist
  • #18 g_signal_emit
  • #19 gtk_button_button_release
  • #20 _gtk_marshal_BOOLEAN__BOXED
  • #21 g_closure_invoke
  • #22 signal_emit_unlocked_R
  • #23 g_signal_emit_valist
  • #24 g_signal_emit
  • #25 gtk_widget_event_internal
  • #26 gtk_propagate_event
  • #27 gtk_main_do_event
  • #28 gdk_event_dispatch
  • #29 g_main_context_dispatch
  • #30 g_main_context_iterate
  • #31 g_main_loop_run
  • #32 gtk_main
  • #33 main
    at main.c line 185

Comment 2 Nick Dowell 2013-07-20 15:01:39 UTC
Looks like a bad 'type' value is being passed to glade_widget_adaptor_get_by_type()

I added some debug output to the code like so:


GladeWidgetAdaptor  *
glade_widget_adaptor_get_by_type (GType  type)
{
	g_printf("glade_widget_adaptor_get_by_type(%s)\n", g_type_name(type));
	if (adaptor_hash != NULL)
		return g_hash_table_lookup (adaptor_hash, &type);
	else
		return NULL;
}


When adding widgets that work, a sensible values were printed to the console, e.g.
glade_widget_adaptor_get_by_type(GtkMenuBar)

However, when trying to add an item to the menu hierarchy, the above code crashes in g_type_name()
Comment 3 Juan Pablo Ugarte 2013-07-20 22:24:06 UTC
First of all make sure you are not getting any relevant warning at init time
then I guess you will have to use gdb to track this issue.
rebuild with debug symbols and no optimization and add a break point at 
glade_widget_adaptor_get_by_type() before add the menu item.
Comment 4 Nick Dowell 2013-07-21 15:53:27 UTC
There are no warning or error messages emitted before hitting this problem.

I have rebuilt with -g -O0, and added some more debug logging to glade_widget_adaptor_get_by_type() to try and shed some light on this.


The following log shows what is going on: http://pastebin.com/raw.php?i=VC0Zk4dZ

At the point of failure, the type (32038896) given to glade_widget_adaptor_get_by_type is that of GtkMenuItem. There was definitely an adaptor registered for this type as can be seen earlier in the log. At the end of the log, however, adaptor_hash no longer has a value for that type... (and g_type_name() crashes)


I have also verified that adaptor_hash is not changing value, and tried some other changes suggested by people on #gnome-hackers -- http://pastebin.com/raw.php?i=bevEVUnd
Comment 5 Juan Pablo Ugarte 2013-07-22 20:00:15 UTC
Try to see if you can spot when the adaptor is being removed from the hash table
btw you can join #glade3 @ irc.gimp.org so we can help you debug it
Comment 6 Nick Dowell 2013-07-22 20:43:03 UTC
Things got even stranger when I added some further diagnostic code.

Even though g_hash_table_lookup fails to find an entry for the type, if I use g_hash_table_foreach to examine the contents of the hash, the entry is there.
Comment 7 Nick Dowell 2013-07-26 20:38:53 UTC
The problem is that the GType value is being truncated to 32 bits.
My original logging statements were not revealing this because I was printing using %d.

The definition of glade_base_editor_signals[SIGNAL_BUILD_CHILD] needs to be fixed, since GType is a pointer-sized type (not uint sized).

I think this means we need a new marshaller of type (OBJECT:OBJECT,POINTER) in gtk-marshallers but am not sure how these should be authored (seems to be generated from glade-marshallers.list)
Comment 8 Nick Dowell 2013-08-11 15:29:07 UTC
This bug can be reproduced on 64-bit Linux by using jemalloc instead of libc's malloc.

  LD_PRELOAD=/usr/local/lib/libjemalloc.so glade-3

jemalloc allocates memory using mmap(), which results in memory addresses above the lower 4GB boundary.

These memory addresses are then being truncated to 32 bits in glade and causing this bug (and potentially others.)

FreeBSD and NetBSD use jemalloc by default so will be affected, and Mac OS X's malloc also returns addresses above 4GB.
Comment 9 Nick Dowell 2013-08-11 15:32:54 UTC
P.S: using jemalloc with glade 3.12.1 and following the same steps results in a segfault
Comment 10 Nick Dowell 2013-08-11 17:43:27 UTC
Created attachment 251301 [details] [review]
Fix for reported issue

The patch fixes the reported issue.
Tested on linux x86_64 with jemalloc.
Comment 11 Juan Pablo Ugarte 2014-05-17 23:28:09 UTC
Good catch!

I used G_TYPE_GTYPE instead of G_TYPE_POINTER and no marshaler because glib-genmarshal does not have a type for GType :s


fixed in master, glade-3-8, glade-3-16 and glade-3-18 branches
Comment 12 Juan Pablo Ugarte 2014-05-17 23:30:21 UTC
hmm I forgot to mention you in the commit log, I will in the next release notes

Thanks for taking care of this!
Comment 13 Juan Pablo Ugarte 2016-05-19 00:11:32 UTC
*** Bug 670764 has been marked as a duplicate of this bug. ***