Gtk3::Application and vfuncs causing segfault

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Gtk3::Application and vfuncs causing segfault

Jeff
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";
}
_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Gtk3::Application and vfuncs causing segfault

Marius Feraru-2
Hi Jeffrey,

On Sun, Jun 3, 2018 at 9:28 PM Jeffrey Ratcliffe <[hidden email]> wrote:
However, if I rewrite the vfunc version to build the UI in the startup method, it segfaults during the Gtk3::ApplicationWindow->new($app) call.

Call SUPER::STARTUP before that; quoting Gtk-3.0→Application→Constructors→new docs:
Concretely, gtk_init() is called in the default handler for the GApplication::startup signal. Therefore, GtkApplication subclasses should chain up in their GApplication::startup handler before using any GTK+ API.

Cheers

_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Gtk3::Application and vfuncs causing segfault

Jeff
Hi Marius,

On Mon, 4 Jun 2018 03:27:46 +0300
Marius Feraru <[hidden email]> wrote:

> Call SUPER::STARTUP before that; quoting
> Gtk-3.0→Application→Constructors→new docs:
>
> > Concretely, gtk_init() is called in the default handler for the
> > GApplication::startup signal. Therefore, GtkApplication subclasses
> > should chain up in their GApplication::startup handler before using
> > any GTK+ API.  

Thanks for you swift response. Indeed, calling SUPER::STARTUP first
solves the problem.

Regards

Jeff
_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list