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();

 return 0;

but it segfauls; here is the backtrace:

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

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?


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