Re: menuitem confusion

On 30.06.2012 21:53, Dave M wrote:
sub Gtk3::RadioMenuItem::new {
         my ($class, $group) = @_;

         return Glib::Object::new( $class, group => $group );

This returns
( Gtk-CRITICAL **:
gtk_radio_menu_item_get_group: assertion `GTK_IS_RADIO_MENU_ITEM
(radio_menu_item)' failed

Note that the assertion refers to gtk_radio_menu_item_get_group. It is due to the "group" property officially being of type GtkRadioMenuItem. So in the Glib::Object::new call above, Glib will create a GValue of this type containing NULL. But under the hood, GtkRadioMenuItem actually accepts a list for the "group" property. Here's the relevant code:

  if (G_VALUE_HOLDS_OBJECT (value))
    slist = gtk_radio_menu_item_get_group ((GtkRadioMenuItem*)
              g_value_get_object (value));
    slist = NULL;
  gtk_radio_menu_item_set_group (radio_menu_item, slist);

So it uses G_VALUE_HOLDS_OBJECT, which is always true when Glib constructed the value, to decide whether the value is a single item or a list. In the former case, it doesn't handle NULL/undef gracefully -- this is where the assertion occurs.

I think the following would work better, given the above constraints:

  sub Gtk3::RadioMenuItem::new {
    my ($class, $group) = @_;
    $group = [] unless defined $group;
    return $class->new ($group);

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