Gtk3::Application and vfuncs causing segfault
- From: Jeffrey Ratcliffe <jffry posteo net>
- To: gtk-perl-list gnome org
- Subject: Gtk3::Application and vfuncs causing segfault
- Date: Sun, 3 Jun 2018 20:28:17 +0200
Unfortunately, the Gtk3::Application examples we were throwing about
before were not very realistic, as they built the UI in the activate
callback/vfunc. However, the logic is that the startup callback/vfunc
is the one that is called first and once only, and the activate
callback immediately afterwards, and then before any open callback.
However, if I rewrite the vfunc version to build the UI in the
startup method, it segfaults during the
Gtk3::ApplicationWindow->new($app) call.
I can make the whole thing work by using a vfunc for the OPEN method
(that doesn't work with callbacks yet) and callbacks everywhere else.
Please find the two versions below in the hope that someone who knows
more about the internals can work out what is causing the segfault.
Regards
Jeff
#!/usr/bin/perl
package MyApp;
BEGIN {
use Glib::Object::Introspection;
Glib::Object::Introspection->setup(
basename => 'Gio',
version => '2.0',
package => 'Glib::IO');
}
use strict;
use warnings;
use Gtk3;
use Glib qw/TRUE FALSE/;
my $window;
use Glib::Object::Subclass qw/Gtk3::Application/;
sub STARTUP {
my ($app) = @_;
print "entering STARTUP with $app\n";
$window = Gtk3::ApplicationWindow->new ($app);
print "after new\n";
$window->set_title ('Welcome to GNOME');
$window->set_default_size (200, 200);
$window->signal_connect ('delete_event' => sub {$app->quit()});
$window->show_all ();
print "leaving STARTUP\n";
return $app->SUPER::STARTUP ();
}
sub ACTIVATE {
my ($app) = @_;
print "entering ACTIVATE\n";
$window->present;
print "leaving ACTIVATE\n";
return $app->SUPER::ACTIVATE ();
}
sub OPEN {
my ($app, $files, $nfiles, $arg3) = @_;
print "in open\n";
use Data::Dumper;
print Dumper($files, $nfiles, $arg3);
for my $file (@$files) {
print $file->get_path(), "\n";
}
}
sub SHUTDOWN {
my ($app) = @_;
print "entering SHUTDOWN\n";
return $app->SUPER::SHUTDOWN ();
}
package main;
my $app = MyApp->new(
application_id => 'app.test',
flags => 'handles-open');
exit $app->run([$0, @ARGV]);
################################################
#!/usr/bin/perl
package MyApp;
BEGIN {
use Glib::Object::Introspection;
Glib::Object::Introspection->setup(
basename => 'Gio',
version => '2.0',
package => 'Glib::IO');
}
use strict;
use warnings;
use Gtk3;
use Glib qw/TRUE FALSE/;
my $window;
use Glib::Object::Subclass qw/Gtk3::Application/;
sub OPEN {
my ($app, $files, $nfiles, $arg3) = @_;
print "in open\n";
use Data::Dumper;
print Dumper($files, $nfiles, $arg3);
for my $file (@$files) {
print $file->get_path(), "\n";
}
}
package main;
my $app = MyApp->new(
application_id => 'app.test',
flags => 'handles-open');
$app->signal_connect('startup' => \&startup_callback );
$app->signal_connect('activate' => \&activate_callback );
$app->signal_connect('shutdown' => \&shutdown_callback );
exit $app->run([$0, @ARGV]);
sub startup_callback {
my ($app) = @_;
print "entering STARTUP with $app\n";
$window = Gtk3::ApplicationWindow->new ($app);
print "after new\n";
$window->set_title ('Welcome to GNOME');
$window->set_default_size (200, 200);
$window->signal_connect ('delete_event' => sub {$app->quit()});
$window->show_all ();
print "leaving STARTUP\n";
}
sub activate_callback {
my ($app) = @_;
print "entering ACTIVATE\n";
$window->present;
print "leaving ACTIVATE\n";
}
sub shutdown_callback {
my ($app) = @_;
# Handle cleanup
print "Goodbye world!\n";
}
[Date Prev][
Date Next] [Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]