GNOME Bugzilla – Bug 94658
TextBuffer insert method using RefPtr<TextBuffer> yields core dump on G_IS_OBJECT assertion
Last modified: 2004-12-22 21:47:04 UTC
Word Description ---------------- When I create a TextBuffer and perform some insertion of text into it, I will eventually get a core dump due to an object integrity check by an assertion. Originally, I was using the TextBuffer in conjunction with a TextView; however, I have narrowed down the sequence of operations that seem to generate this problem. In addition, the assertion appears to be at the time of an "un-reference" by the RefPtr of the TextBuffer. To simplify the problem I wrote a *very* simple test program and provide the following to assist debugging: File: t.cc ------------------ #include <gtkmm.h> int main (int argc, char** argv) { Glib::RefPtr<Gtk::TextBuffer> rptxtbuf = Gtk::TextBuffer::create (); rptxtbuf->insert_at_cursor ("This line is a test.\n"); return 0; } ------------------- In Bash shell: $ g++ t.cc -g `pkg-config gtkmm-2.0 --cflags --libs` -o t $ ./t (process:21719): GLib-GObject-CRITICAL **: gtype.c:1806:g_type_register_static(): initialization assertion failed, use g_type_init() prior to this function Segmentation fault (core dumped) $ gdb ./t core GNU gdb Red Hat Linux (5.2-2) Copyright 2002 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-redhat-linux"... Core was generated by `./t'. Program terminated with signal 11, Segmentation fault. Reading symbols from /usr/g2dev/lib/libgtkmm-1.3.so.17...done. Loaded symbols for /usr/g2dev/lib/libgtkmm-1.3.so.17 Reading symbols from /usr/g2dev/lib/libgdkmm-1.3.so.17...done. Loaded symbols for /usr/g2dev/lib/libgdkmm-1.3.so.17 Reading symbols from /usr/g2dev/lib/libatkmm-0.0.so.17...done. Loaded symbols for /usr/g2dev/lib/libatkmm-0.0.so.17 Reading symbols from /usr/g2dev/lib/libgtk-x11-2.0.so.0...done. Loaded symbols for /usr/g2dev/lib/libgtk-x11-2.0.so.0 Reading symbols from /usr/g2dev/lib/libpangomm-0.0.so.17...done. Loaded symbols for /usr/g2dev/lib/libpangomm-0.0.so.17 Reading symbols from /usr/g2dev/lib/libglibmm-1.3.so.17...done. Loaded symbols for /usr/g2dev/lib/libglibmm-1.3.so.17 Reading symbols from /usr/local/lib/libsigc-1.1.so.5...done. Loaded symbols for /usr/local/lib/libsigc-1.1.so.5 Reading symbols from /usr/g2dev/lib/libgdk-x11-2.0.so.0...done. Loaded symbols for /usr/g2dev/lib/libgdk-x11-2.0.so.0 Reading symbols from /usr/local/lib/libatk-1.0.so.0...done. Loaded symbols for /usr/local/lib/libatk-1.0.so.0 Reading symbols from /usr/g2dev/lib/libgdk_pixbuf-2.0.so.0...done. Loaded symbols for /usr/g2dev/lib/libgdk_pixbuf-2.0.so.0 Reading symbols from /usr/local/lib/libpangoxft-1.0.so.0...done. Loaded symbols for /usr/local/lib/libpangoxft-1.0.so.0 Reading symbols from /usr/local/lib/libpangox-1.0.so.0...done. Loaded symbols for /usr/local/lib/libpangox-1.0.so.0 Reading symbols from /usr/local/lib/libpango-1.0.so.0...done. Loaded symbols for /usr/local/lib/libpango-1.0.so.0 Reading symbols from /usr/g2dev/lib/libgobject-2.0.so.0...done. Loaded symbols for /usr/g2dev/lib/libgobject-2.0.so.0 Reading symbols from /usr/g2dev/lib/libgmodule-2.0.so.0...done. Loaded symbols for /usr/g2dev/lib/libgmodule-2.0.so.0 Reading symbols from /lib/libdl.so.2...done. Loaded symbols for /lib/libdl.so.2 Reading symbols from /usr/g2dev/lib/libglib-2.0.so.0...done. Loaded symbols for /usr/g2dev/lib/libglib-2.0.so.0 Reading symbols from /usr/lib/libstdc++-libc6.2-2.so.3...done. Loaded symbols for /usr/lib/libstdc++-libc6.2-2.so.3 Reading symbols from /lib/i686/libm.so.6...done. Loaded symbols for /lib/i686/libm.so.6 Reading symbols from /lib/i686/libc.so.6...done. Loaded symbols for /lib/i686/libc.so.6 Reading symbols from /usr/X11R6/lib/libXft.so.1...done. Loaded symbols for /usr/X11R6/lib/libXft.so.1 Reading symbols from /usr/X11R6/lib/libXrender.so.1...done. Loaded symbols for /usr/X11R6/lib/libXrender.so.1 Reading symbols from /usr/X11R6/lib/libXext.so.6...done. Loaded symbols for /usr/X11R6/lib/libXext.so.6 Reading symbols from /usr/X11R6/lib/libX11.so.6...done. Loaded symbols for /usr/X11R6/lib/libX11.so.6 Reading symbols from /usr/lib/libfreetype.so.6...done. Loaded symbols for /usr/lib/libfreetype.so.6 Reading symbols from /lib/ld-linux.so.2...done. Loaded symbols for /lib/ld-linux.so.2
+ Trace 28124
---------------------------- (Although it may not be needed... Linux kernel is version 2.4.18-10, gcc is version 2.96) That is as much information I can give at the moment. You should be able to see the development environment (ie: versions of related packages) in the gdb listing. Hope this speel helps with the debugging. Regards, Frank
This test code should not be expected to work, because you do not initialize gtkmm or gtk - for example, you should use Gtk::Main, as we do in the examples. Also, try running your application with --g-fatal-warnings to debug the cause of the warning.
Understood. The test program is an over-simplified version of the more complex one that I have; however, I still get the same result either way. With that in mind, I pared the test program until I could duplicate the problem consistently. In any case, I now provide the results of the modified test program with only a Gtk::Main object added. I also ran the test program with the --g-fatal-warnings flag. The stack trace still show the problem in the "un-ref" of the TextBuffer RefPtr. Thanks, Murray, for taking a look... if I can be of further assistance I will continue to work with you on this problem and consider helping with sections that I can become familiar with for future developments. t.cc -------------------- #include <gtkmm.h> int main (int argc, char** argv) { Gtk::Main application (argc, argv); Glib::RefPtr<Gtk::TextBuffer> rptxtbuf = Gtk::TextBuffer::create(); rptxtbuf->insert_at_cursor ("This line is a test.\n"); return 0; } --------------------------- In Bash Shell: $ g++ -g t.cc `pkg-config gtkmm-2.0 --cflags --libs` -o t $ ./t --g-fatal-warnings GLib-GObject-CRITICAL **: file gobject.c: line 1307 (g_object_unref): assertion `G_IS_OBJECT (object)' failed aborting... Aborted (core dumped) $ gdb ./t core GNU gdb Red Hat Linux (5.2-2) Copyright 2002 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-redhat-linux"... Core was generated by `./t --g-fatal-warnings'. Program terminated with signal 6, Aborted. Reading symbols from /usr/g2dev/lib/libgtkmm-1.3.so.17...done. Loaded symbols for /usr/g2dev/lib/libgtkmm-1.3.so.17 Reading symbols from /usr/g2dev/lib/libgdkmm-1.3.so.17...done. Loaded symbols for /usr/g2dev/lib/libgdkmm-1.3.so.17 Reading symbols from /usr/g2dev/lib/libatkmm-0.0.so.17...done. Loaded symbols for /usr/g2dev/lib/libatkmm-0.0.so.17 Reading symbols from /usr/g2dev/lib/libgtk-x11-2.0.so.0...done. Loaded symbols for /usr/g2dev/lib/libgtk-x11-2.0.so.0 Reading symbols from /usr/g2dev/lib/libpangomm-0.0.so.17...done. Loaded symbols for /usr/g2dev/lib/libpangomm-0.0.so.17 Reading symbols from /usr/g2dev/lib/libglibmm-1.3.so.17...done. Loaded symbols for /usr/g2dev/lib/libglibmm-1.3.so.17 Reading symbols from /usr/local/lib/libsigc-1.1.so.5...done. Loaded symbols for /usr/local/lib/libsigc-1.1.so.5 Reading symbols from /usr/g2dev/lib/libgdk-x11-2.0.so.0...done. Loaded symbols for /usr/g2dev/lib/libgdk-x11-2.0.so.0 Reading symbols from /usr/local/lib/libatk-1.0.so.0...done. Loaded symbols for /usr/local/lib/libatk-1.0.so.0 Reading symbols from /usr/g2dev/lib/libgdk_pixbuf-2.0.so.0...done. Loaded symbols for /usr/g2dev/lib/libgdk_pixbuf-2.0.so.0 Reading symbols from /usr/local/lib/libpangoxft-1.0.so.0...done. Loaded symbols for /usr/local/lib/libpangoxft-1.0.so.0 Reading symbols from /usr/local/lib/libpangox-1.0.so.0...done. Loaded symbols for /usr/local/lib/libpangox-1.0.so.0 Reading symbols from /usr/local/lib/libpango-1.0.so.0...done. Loaded symbols for /usr/local/lib/libpango-1.0.so.0 Reading symbols from /usr/g2dev/lib/libgobject-2.0.so.0...done. Loaded symbols for /usr/g2dev/lib/libgobject-2.0.so.0 Reading symbols from /usr/g2dev/lib/libgmodule-2.0.so.0...done. Loaded symbols for /usr/g2dev/lib/libgmodule-2.0.so.0 Reading symbols from /lib/libdl.so.2...done. Loaded symbols for /lib/libdl.so.2 Reading symbols from /usr/g2dev/lib/libglib-2.0.so.0...done. Loaded symbols for /usr/g2dev/lib/libglib-2.0.so.0 Reading symbols from /usr/lib/libstdc++-libc6.2-2.so.3...done. Loaded symbols for /usr/lib/libstdc++-libc6.2-2.so.3 Reading symbols from /lib/i686/libm.so.6...done. Loaded symbols for /lib/i686/libm.so.6 Reading symbols from /lib/i686/libc.so.6...done. Loaded symbols for /lib/i686/libc.so.6 Reading symbols from /usr/X11R6/lib/libXft.so.1...done. Loaded symbols for /usr/X11R6/lib/libXft.so.1 Reading symbols from /usr/X11R6/lib/libXrender.so.1...done. Loaded symbols for /usr/X11R6/lib/libXrender.so.1 Reading symbols from /usr/X11R6/lib/libXext.so.6...done. Loaded symbols for /usr/X11R6/lib/libXext.so.6 Reading symbols from /usr/X11R6/lib/libX11.so.6...done. Loaded symbols for /usr/X11R6/lib/libX11.so.6 Reading symbols from /usr/lib/libfreetype.so.6...done. Loaded symbols for /usr/lib/libfreetype.so.6 Reading symbols from /lib/ld-linux.so.2...done. Loaded symbols for /lib/ld-linux.so.2 Reading symbols from /usr/X11R6/lib/X11/locale/common/xlcDef.so.2...done. Loaded symbols for /usr/X11R6/lib/X11/locale/common/xlcDef.so.2 Reading symbols from /lib/libnss_files.so.2...done. Loaded symbols for /lib/libnss_files.so.2 Reading symbols from /usr/lib/gconv/ISO8859-1.so...done. Loaded symbols for /usr/lib/gconv/ISO8859-1.so
+ Trace 28152
Regards, Frank Shim
Could you try it with plain GTK+ C code, to see if it's a problem in gtkmm?
Okay... Here is my attempt at duplicating the test program in GTK+ 2.0. t.c ----------------------- #include <gtk/gtk.h> #include <gtk/gtktextbuffer.h> #include <gtk/gtktextiter.h> int main (int argc, char** argv) { GtkTextBuffer* txtbuf; gtk_init (&argc, &argv); txtbuf = gtk_text_buffer_new (NULL); gtk_text_buffer_insert_at_cursor (txtbuf, "This line is a test\n", 20); return 0; } -------------------------- In Bash Shell $ gcc -g t.c `pkg-config gtk+-2.0 --cflags --libs` -o tt $ ./tt $ ./tt --g-fatal-warnings $ -------------------------- No core dumps; however, it may be due to the fact that I will have to do the equivalent of 'C++ destructor like' calls in GTK+ 2.0. My thinking is that it has more to do with the RefPtr<> implementation of TextBuffer class referencing/deferencing. Let me know what you think. Regards, Frank Shim
I tried the C++ test code without problems. I seem to remember that we fixed something like this recently so maybe you should try a newer version. Please reopen the bug if it's still a problem.