GNOME Bugzilla – Bug 119049
Gdk::Display::open() ref-count problem.
Last modified: 2004-12-22 21:47:04 UTC
Basically, if I request a Gdk::Display object using the open() method, the RefPtr returned causes an exception when the reference leaves scope. This short program reproduces the issue on Gentoo with the latest ebuild version (2.2.5) installed: #include <iostream> #include <gdkmm/display.h> #include <gtkmm/main.h> int main(int argc, char **argv) { Gtk::Main kit(argc, argv); std::cout << "Print this." << std::endl; { Glib::RefPtr<Gdk::Display> display = Gdk::Display::open(":0.0"); std::cout << "RefPtr is still good." << std::endl; } std::cout << "This will never print." << std::endl; return 0; } Compiling this against the gtkmm and gdkmm libraries will have this output: $ g++ -o test test.cc `pkg-config --libs --cflags gdkmm-2.0 gtkmm-2.0` $ ./test Print this. RefPtr is still good. Segmentation fault It's pretty clear where the problem is. To make it even more explicit adding a call to display.clear() right above the "RefPtr is still good." line will keep that from being printed.
I guess we need an extra "refreturn" here: http://cvs.gnome.org/lxr/source/gtkmm-root/gdk-src/display.hg#43 open_default() migtht need the same thing.
That's probably right. I'm not familiar with gtkmm's internals, but I ran into this on the gtkmm-list archives when looking for a solution: http://mail.gnome.org/archives/gtkmm-list/2003-January/msg00228.html This person was having a problem with open_default()--as I recall. And a similar suggestion was made.
A patch would be welcome. Otherwise, it will take me a week or so to get to this.
Fixed in cvs (we will make a new release soon too). Please confirm that it works for you.