GNOME Bugzilla – Bug 110206
removing items from a Ctk::Combo crashes
Last modified: 2004-12-22 21:47:04 UTC
When I try to remove some items from a Gtk::Combo (eg from a Gtk::ComboDropDown), the program crashes. sample program: #include <gtkmm/main.h> #include <gtkmm/window.h> #include <gtkmm/combo.h> #include <list> class SampleWindow: public Gtk::Window { public: SampleWindow() { add(_combo); std::list<Glib::ustring> listStrings; listStrings.push_back("something"); listStrings.push_back("something else"); listStrings.push_back("something or other"); _combo.set_popdown_strings(listStrings); _combo.get_list()->children().clear(); // <- CRASH HERE show_all_children(); } private: Gtk::Combo _combo; }; int main(int argc, char *argv[]) { Gtk::Main kit(argc, argv); SampleWindow sw; Gtk::Main::run(sw); return 0; }
Could someone check this on Linux?
And please _attach_ test code in future.
Tried it out on Linux with version 2.0.2, and it segfaults. Backtrace: (gdb) bt
+ Trace 35752
This one looks serious. I think that ComboDropDownList should be using List_Cpp_iterator instead of List_Iterator, because at the moment it casts a C instance from GList::node->data directly to C++ instance. In fact, I don't think List_Iterator should ever work. I would really like Daniel Elsner to take a look too. This patch seems to fix things, but it would be API or ABI breaking, so I'm changing this to a 2.4 bug. I guess it's a good thing that we generally have dual STL-like/GTK+-like for these things. Gtk::Combo is kind of a special case because we had to hide the deprecated GtkList widget. Hopefully it's OK for you to completely rebuild the list of items.
Hmm, now I find that that patch isn't really on my floppy. Well, it just added this line GP_LIST_ITER(Glib::List_Cpp_Iterator<GtkListItem, ComboDropDownItem>) like in menushell: http://cvs.gnome.org/lxr/source/gtkmm-root/gtk-src/menushell.hg#53
the combo.h file doesn't change if I add the line. More, if I erase the combo.h generated file, compilation complains that it doesn't have any rule to generate it...
That's unusual. You could try running autogen.sh, or try it from cvs. But anyway, this won't be very helpful to you now because you probably want to continue using the gtkmm 2.2 stable API instead of gtkmm 2.4.
I have applied this to gtkmm 2.4 so that people can test it out. (I need to check in some important install/pkg-config fixes to gtkmm 2.4 later today).
By the way, for gtkmm 2.2 these are the workarounds that I can think of: 1. Remove all the items and add them again. (Removing might need 2.) 2. Use GTK+ functions, after using gobj() to get the C instance.