Re: [gtkmm] weird segfault



Rui Lopes wrote:

Hello all,

I have this code,

int main(int argc, char *argv[])
{
 Gtk::Main kit(argc, argv);
 Gtk::Window window;

 Glib::RefPtr<Gdk::Display> refDisplay = Gdk::Display::get_default();
 GdkDisplay *pGdkDisplay = refDisplay->gobj();

 Gtk::Main::run(window);
 return 0;
}

but it segfauls; here is the backtrace:

Program received signal SIGSEGV, Segmentation fault.
0x405b4a70 in _gdk_windowing_set_default_display () from
/usr/lib/libgdk-x11-2.0.so.0
(gdb) bt
#0  0x405b4a70 in _gdk_windowing_set_default_display () from
/usr/lib/libgdk-x11-2.0.so.0
#1  0x4059d307 in gdk_display_manager_set_default_display () from
/usr/lib/libgdk-x11-2.0.so.0
#2  0x40595892 in gdk_display_dispose () from /usr/lib/libgdk-x11-2.0.so.0
#3  0x405b480d in gdk_display_x11_dispose () from
/usr/lib/libgdk-x11-2.0.so.0
#4  0x40688bdd in g_object_last_unref () from /usr/lib/libgobject-2.0.so.0
#5  0x4055d8c2 in Glib::ObjectBase::unreference() const () from
/usr/lib/libglibmm-2.0.so.1
#6  0x080496e0 in ~RefPtr (this=0xbffff980) at
/usr/include/gtkmm-2.0/glibmm/refptr.h:176
#7  0x080495a8 in main (argc=1, argv=0xbffffa34) at wininfo.cpp:114
#8  0x40830e34 in __libc_start_main () from /lib/libc.so.6
(gdb)


note: line #6 is the destructor of RefPtr.
It looks to me like the RefPtr is keeping the Display object alive until the main() routine is finished, even though the X11 connection is destroyed before returning from run(). So when the Display object is finally destroyed, the underlying GTK+ routines trip over something (a stale pointer, perhaps) and fall down.

You could try clearing your RefPtr before entering run() to avoid this. Presumably you won't need it after that point?

..mj




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]