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 78578 - Segfault when calling the MenuItem superconstructor.
Segfault when calling the MenuItem superconstructor.
Status: RESOLVED NOTABUG
Product: gtkmm
Classification: Bindings
Component: general
2.0
Other Linux
: Normal normal
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on:
Blocks:
 
 
Reported: 2002-04-13 02:31 UTC by Matthew Tuck
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Matthew Tuck 2002-04-13 02:31:50 UTC
Hi, I'm quite new to Gtkmm, and my C++ is a bit rusty, but I don't think
the program below has any errors on my part.  It seems to crash in
container.cc in GTK so I'm not sure if the fault is mine, GTKMM, GTK+ or
GCC.

I've tried this on 1.3.8 and the bug occurs, and then tried it on CVS. 
My compiler is GCC 2.95.4.

I reduced the program right down and this is what I got:

--- cut ---
#include <gtkmm.h>

class NewNodeMenuItem : public Gtk::MenuItem {
public:

  NewNodeMenuItem() : Gtk::MenuItem("Node") {}
  Gtk::Window *my_window;

};

int main(int argc, char *argv[]) {

  Gtk::Main main_instance (&argc, &argv);

  new NewNodeMenuItem();

  return 0;

}
--- cut ---

It seems the call to the superconstructor with a parameter causes a
segfault.  Any of the following seems to remove the problem:

- calling the MenuItem constructor normally, ie with new
- calling it without a parameter, ie to create a separator
- removing my_window from the class

To workaround I have used add_label.
Comment 1 Murray Cumming 2002-04-17 01:38:02 UTC
Confirmed. It seems to fail somewhere in a dynamic_cast<> during the
Container::add() call. Here's the backtrace

(gdb) backtrace
  • #0 __class_type_info::do_find_public_subobj
    from /gnome/head/INSTALL/lib/libsigc-1.1.so.2
  • #1 __class_type_info::do_find_public_subobj
    from /gnome/head/INSTALL/lib/libsigc-1.1.so.2
  • #2 __class_type_info::do_find_public_subobj
    from /gnome/head/INSTALL/lib/libsigc-1.1.so.2
  • #3 __class_type_info::do_find_public_subobj
    from /gnome/head/INSTALL/lib/libsigc-1.1.so.2
  • #4 __class_type_info::do_find_public_subobj
    from /gnome/head/INSTALL/lib/libsigc-1.1.so.2
  • #5 __class_type_info::do_find_public_subobj
    from /gnome/head/INSTALL/lib/libsigc-1.1.so.2
  • #6 __user_type_info::dyncast
    from /gnome/head/INSTALL/lib/libsigc-1.1.so.2
  • #7 __dynamic_cast_2
  • #8 Gtk::Container_Class::add_callback
    at container.cc line 385
  • #9 g_cclosure_marshal_VOID__OBJECT
    at gmarshal.c line 636
  • #10 g_type_class_meta_marshal
    at gclosure.c line 514
  • #11 g_closure_invoke
    at gclosure.c line 437
  • #12 signal_emit_unlocked_R
    at gsignal.c line 2271
  • #13 g_signal_emit_valist
    at gsignal.c line 2100
  • #14 gtk_signal_emit
    at gtksignal.c line 355
  • #15 gtk_container_add
    at gtkcontainer.c line 859
  • #16 Gtk::Container::add
    at ../../gtk/gtkmm/container.h line 97
  • #17 Gtk::MenuItem::add_accel_label
    at menuitem.cc line 56
  • #18 Gtk::MenuItem::MenuItem
  • #19 main
    at main.cc line 24
  • #20 __libc_start_main
    at ../sysdeps/generic/libc-start.c line 129

Comment 2 Brandon Johnson 2002-05-10 00:55:49 UTC
There are two constructors for MenuItem
1. takes an arg of Widget&
2. takes two args of GLib::ustring&, and bool mnemonic = false
because of this ustring& I am going to try a little modification to
the code to see if the following works.
 NewNodeMenuItem() : Gtk::MenuItem(new Glib::ustring("Node"))
Will paste in results.
Comment 3 Murray Cumming 2002-05-10 14:56:42 UTC
You shouldn't have a new there. That would result in a Glib::ustring*,
not a Glib::ustring. Anyway, I don't expect this to make any difference.
Comment 4 Brandon Johnson 2002-05-21 02:16:52 UTC
Nope, your right no difference. After stepping through the code in
order to see where the segfault occurs though, it seems to be an issue
with the Glib::Object constructor. when it hits that point it crashes.
I'm still investigating. (need to find out what mutable means) wasn't
around when I learned c++ ;)
Comment 5 Brandon Johnson 2002-05-21 02:27:50 UTC
more accurately it seems to be in the Glib::ObjectBase constructor and
with the member initialization list.

ObjectBase::ObjectBase()
:
  gobject_ (0),
  cpp_destruction_in_progress_(false)
{
}
it looked like it was when the object was initializing
cpp_desctruction_in_progress_ member.

Im still trying to understand how this process should work.
Comment 6 Brandon Johnson 2002-05-22 03:57:27 UTC
Here is the latest. I have studied the code and nothing looks like its
obviously misbehaving. After toying with the source and debugging I
have come up with the following.

debug with original code
--- Original code ---

(gdb) step
0x0804afa6 in NewNodeMenuItem::NewNodeMenuItem (this=0x806e210,
__in_chrg=1) at gtkmenuitembug.cc:6
(gdb) 
0x0804b1b3 in SigC::ObjectBase::ObjectBase (this=0x806e22c) at
/usr/local/include/sigc++-1.2/sigc++/object.h:74
(gdb) 
0x0804afd8 in NewNodeMenuItem::NewNodeMenuItem (this=0x806e210,
__in_chrg=1) at gtkmenuitembug.cc:6
(gdb) 
Glib::ObjectBase::ObjectBase (this=0x806e234, __in_chrg=0) at
objectbase.cc:39
(gdb) 
(gdb) 

Program received signal SIGSEGV, Segmentation fault.
0x40435c75 in __class_type_info::do_find_public_subobj (this=0x0,
boff=0, subtype=@0x0, objptr=0x0, subptr=0x0) from
/usr/local/lib/libsigc-1.1.so.3
(gdb) 

--- orignal code ---

if any of the orginal suggestions are used to work around the issue it
works, and if I change the class to

class NewNodeMenuItem : public Gtk::MenuItem {
public:
	NewNodeMenuItem() : Gtk::MenuItem("Node") {};
	int i;
	Gtk::Window *my_window;
};

then it works too. <scratches head for a minute>
It looks like a compiler issue. The class is doing exactly the same
thing just adding a different data memeber.


when I do a backtrace with the orginal code I get:

(gdb) step

Program received signal SIGSEGV, Segmentation fault.
0x40435c75 in __class_type_info::do_find_public_subobj (this=0x0,
boff=0, subtype=@0x0, objptr=0x0, subptr=0x0) from
/usr/local/lib/libsigc-1.1.so.3
(gdb) backtrace
  • #0 __class_type_info::do_find_public_subobj
    from /usr/local/lib/libsigc-1.1.so.3
  • #1 ??
  • #2 __class_type_info virtual table
    from /usr/local/lib/libsigc-1.1.so.3
  • #3 ??

... so my gut feel is a compiler issue. 
(virtual table is the compiler keeping track of virtual base classes) 
Any comments? 

BTW, I am using a default Mandrake 8.2 installation with a dedicated
environment for gtk2/gtkmm2 development.
ie. source packages in /usr/local/src
packages are as follows in /usr/local/src/<dir>

atk-1.0.1/
glib-2.0.1/
gtk+-2.0.2/
gtkmm-1.3.14/
gtkmm_hello-0.1.0/
intltool-0.18/
libsigc++-1.1.10/
pango-1.0.1/
pkgconfig-0.12.0/

and environment..
PATH=/usr/local/bin:$PATH
LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

This one is a tricky one. ;)
Comment 7 Murray Cumming 2002-08-28 14:09:55 UTC
Maybe someone could try changing that cpp_destruction_in_progress_ to
a different type. Maybe an int, for example. 
Comment 8 Murray Cumming 2002-08-28 14:38:36 UTC
Strangely, valgrind doesn't report any problems - not even a crash.

valgrind test
==515== valgrind-20020426, a memory error detector for x86 GNU/Linux.
==515== Copyright (C) 2000-2002, and GNU GPL'd, by Julian Seward.
==515== Estimated CPU clock rate is 805 MHz
==515== For more details, rerun with: -v
==515== 
==515== 
==515== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
==515== malloc/free: in use at exit: 6086 bytes in 89 blocks.
==515== malloc/free: 104 allocs, 15 frees, 7891 bytes allocated.
==515== For a detailed leak analysis,  rerun with: --leak-check=yes
==515== For counts of detected errors, rerun with: -v
Comment 9 Harald Hopfes 2002-08-28 14:51:04 UTC
The following also crashes when __VALUE__ is one of the following:
0, 5, 6, 7, 8

####################################################

#include <gtkmm.h>
#include <iostream>

class NewClass : public Gtk::ImageMenuItem {
public:

  NewClass() : Gtk::ImageMenuItem("String") {}
  char buf[__VALUE__];
  Gtk::Window *my_window;

};

int main(int argc, char *argv[]) {

  Gtk::Main main_instance (&argc, &argv);
cout << "Sizeof Object is : " << sizeof(NewClass) << endl;
  new NewClass();

  return 0;

}

####################################################
Comment 10 Murray Cumming 2002-08-28 15:02:16 UTC
I should have run
valgrind .libs/lt-test
intead.

This seem more helpful:

==569== Conditional jump or move depends on uninitialised value(s)
==569==    at 0x404EF58A:
__class_type_info::do_find_public_subobj(int, type_info const &, void
*, void *) const (../../gcc/cp/tinfo.cc:773)
==569==    by 0x404EF629:
__class_type_info::do_find_public_subobj(int, type_info const &, void
*, void *) const (../../gcc/cp/tinfo.cc:773)
==569==    by 0x404EF629:
__class_type_info::do_find_public_subobj(int, type_info const &, void
*, void *) const (../../gcc/cp/tinfo.cc:773)
==569==    by 0x404EF629:
__class_type_info::do_find_public_subobj(int, type_info const &, void
*, void *) const (../../gcc/cp/tinfo.cc:773)
==569==    by 0x404EF629:
__class_type_info::do_find_public_subobj(int, type_info const &, void
*, void *) const (../../gcc/cp/tinfo.cc:773)
==569==    by 0x404EED45: __user_type_info::dyncast(int, type_info
const &, void *, type_info const &, void *) const
(../../gcc/cp/tinfo.cc:773)
==569==    by 0x404F06A3: __dynamic_cast_2 (../../gcc/cp/tinfo2.cc:773)
==569==    by 0x40430905:
Gtk::Container_Class::add_callback(_GtkContainer *, _GtkWidget *)
(container.cc:496)
==569==    by 0x4080E7C5: g_cclosure_marshal_VOID__OBJECT (gmarshal.c:639)
==569==    by 0x407F9393: g_type_class_meta_marshal (gclosure.c:514)
==569==    by 0x407F8F9A: g_closure_invoke (gclosure.c:442)
==569==    by 0x4080C918: signal_emit_unlocked_R (gsignal.c:2183)
==569==    by 0x4080B63E: g_signal_emit_valist (gsignal.c:2100)
==569==    by 0x405F74ED: gtk_signal_emit (gtksignal.c:357)
==569==    by 0x40564A36: gtk_container_add (gtkcontainer.c:860)
==569==    by 0x4042FF19: Gtk::Container::add(Gtk::Widget &)
(container.cc:103)
==569==    by 0x404471B5: Gtk::MenuItem::add_accel_label(Glib::ustring
const &, bool) (menuitem.cc:69)
==569==    by 0x4044703D: Gtk::MenuItem::MenuItem(int, Glib::ustring
const &, bool) (menuitem.cc:59)
==569==    by 0x804AF01: main (main.cc:6)
==569==    by 0x4092C507: __libc_start_main
(../sysdeps/generic/libc-start.c:129)
Comment 11 Murray Cumming 2002-08-28 16:34:12 UTC
This problem definitely happens in Container_Class::add_callback(),
during the dynamic_cast<>.
Comment 12 Harald Hopfes 2002-08-28 17:15:03 UTC
The following link might be interesting???

http://gcc.gnu.org/ml/gcc-bugs/2001-08/msg00320.html
Comment 13 Harald Hopfes 2002-08-28 17:18:42 UTC
Sorry, this one is better:

http://gcc.gnu.org/ml/gcc-bugs/2002-07/msg00720.html
Comment 14 Murray Cumming 2002-08-28 17:25:02 UTC
Possibly, but that's not a real test. I don't think that a shared
standalone is meaningful.

What compiler are you using? I'm using gcc 2.96RH on RH7.2. I would
like to hear from people using gcc 3.1 and 3.2.

Comment 15 Murray Cumming 2002-08-28 17:26:02 UTC
Michael, could you try this on your Sun compiler. Maybe it will give
us a clue.
Comment 16 Murray Cumming 2002-08-28 17:26:33 UTC
Michael, could you try this on your Sun compiler. Maybe it will give
us a clue.
Comment 17 Harald Hopfes 2002-08-28 17:28:26 UTC
I'm using gcc 2.96RH on RH7.1.
Comment 18 Murray Cumming 2002-08-28 18:00:25 UTC
This isn't specific to MenuItem. It happens with Button too - its
Button("something") constructor also adds a child widget.

For, now the workaround would be to use the default constructor and
add the child widget manually in your own constructor.
Comment 19 Jarek Dukat 2002-08-28 18:56:04 UTC
I checked this problem with g++-3.2, gtkmm 1.3.21, libsigc++ 1.1.13 and the test proggy did not crash. It seems to be a compiler problem.
Comment 20 Martin Schulze 2002-08-28 19:45:05 UTC
I experience the segfault with gcc 2.95.3. Me too, I get stuck during
the dynamic cast in Gtk::Container_Class::add_callback(). However the
argument passed to dynamic_cast() is 0x1. Stepping through the code
_before_ the segfault happens, I find that our instantiation of the
class NewNodeMenuItem retrieved with g_object_get_qdata(object,
Glib::quark_) in ObjectBase::_get_current_wrapper(object) seems to be
corrupted. E.g. the data member SigC::ObejctBase::control_ suddenly is
non-zero and points to some undefined piece of memory. During
initialization of the wrapper I can't see anything abnormal. All data
seems perfectly valid when stored with g_object_set_qdata_full() in 
ObjectBase::_set_current_wrapper().
Comment 21 Murray Cumming 2002-08-29 08:19:05 UTC
Martin, I find that debuggers and printf give me a variety of
different values for the pointers. Basically, that memory is corrupted.

I remember Karl Nelson talking about a gcc bug that prevented use of
dynamic_cast in either constructors or destructors. This looks like
exactly that. It seems to be fixed in later versions of gcc, and there
are workarounds for older compilers, so I'm thinking of closing this bug.
Comment 22 Harald Hopfes 2002-08-29 08:51:56 UTC
Does that mean, you will include a workaround inside gtkmm?
Comment 23 Murray Cumming 2002-08-29 09:32:02 UTC
You already have workarounds - use different constructors. I don't see
how to workaround it inside gtkmm, but I would look at any patch that
you give us.
Comment 24 Andreas Holzmann 2002-08-29 10:06:19 UTC
As others already said the problem seems to occur in Gtk::Container.
It seems that you get the segmentation faults whenever you extend
a class that is derived from Gtk::Container. I got this because
I have extended Gtk::Window (gcc 2.95). The symptoms are the same as
described by Martin Schulze when I add a Gtk::VBox inside my constructor.
It seems to be a compiler problem because I don't have these problems
when I use gcc 3.0 or gcc 3.2. 
Maybe we should add a comment to the system requirements of the gtkmm
library that users should use a gcc version > 2.95?
Comment 25 Harald Hopfes 2002-08-29 10:32:22 UTC
> Maybe we should add a comment to the system requirements of the 
> gtkmm library that users should use a gcc version > 2.95?

That would be wise!
Comment 26 Murray Cumming 2002-08-29 11:13:42 UTC
Andreas, I only expect you to have this problem when you use a 
constructor that adds a child widget, not when you use _any_ 
constructor. If you think that it is impossible to derive from any 
Container then please give me test code. I really doubt it because 
there are lots of classes that derive from Container and they work 
fine.

Yes, we do need to put this in the FAQ. We would tell people to use 
the workaround or upgrade their compiler if they find this problem. A 
later gcc is _not_ a requirement for gtkmm, because people don't 
_need_ to use those convenience constructors.
Comment 27 Andreas Holzmann 2002-08-29 11:33:27 UTC
Murray, yes you're right. My Gtk::Window subclass calls add() in its
constructor (like in the Gtk::MenuItem problem). I also agree that 
gcc > 2.95 is not a strict requirement.

Maybe the old gcc has a problem working with object that are not yet
fully initialized. The add() method call triggers some callback
mechanisms that use the pointer of the new object. But as we are still
in its constructor, object initialization is not yet fully finished.
Comment 28 Murray Cumming 2002-08-29 12:58:29 UTC
Yes, I think it's a quite-well known dynamic_cast<> gcc bug. But we
were confusing ourselves with other stuff. It would be nice if someone
could patch the FAQ, ideally with a link to an actual gcc bug report.