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

action->get_proxies during connect-proxy emit



The program below gets some strange errors

    GLib-GObject-CRITICAL **: g_object_ref_sink: assertion `G_IS_OBJECT (object)' failed at /home/gg/bug/perl-proxies/foo.pl line 41.
    ...

It's supposed to be just reading out $action->get_proxies, at

    my @widgets = $action->get_proxies;

but something fishy happens.  I wondered if the wrapper for that func
shouldn't be doing a ref_sink on the widgets in the list.  Avoiding that
improves it, but is still not quite right if you're sitting on other
references to the uimanager's widgets.

(Of course perhaps there's some refcounting dodginess in gtk itself.  It
only seems to go wrong if you get_proxies during a connect-proxy signal
emission.)

use strict;
use warnings;
use Gtk2 '-init';

my $toplevel = Gtk2::Window->new ('toplevel');

my $actions = Gtk2::ActionGroup->new ("Actions");
$actions->add_actions
  ([
    [ 'FileMenu',   undef,    '_File'  ],
    [ 'Quit',     'gtk-quit',             undef,
      undef, # accelerator -- don't really want the usual Control-Q
      undef, \&_do_action_quit
    ],
   ]);
sub _do_action_quit {
  Gtk2->main_quit;
}

$actions->signal_connect (connect_proxy => \&_do_connect_proxy);
sub _do_connect_proxy {
  my ($actions, $action, $widget) = @_;
  print "connect_proxy $widget\n";
  my @widgets = $action->get_proxies;
  print @widgets,"\n";
}

my $ui = Gtk2::UIManager->new;
$ui->insert_action_group ($actions, 0);

$ui->add_ui_from_string (<<'HERE');
<ui>
  <menubar name='MenuBar'>
    <menu action='FileMenu'>
      <menuitem action='Quit'/>
    </menu>
  </menubar>
</ui>
HERE

my $menubar = $ui->get_widget('/MenuBar');
$toplevel->add ($menubar);

$toplevel->add_accel_group ($ui->get_accel_group);

$toplevel->show_all;
Gtk2->main;
exit 0;


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