GNOME Bugzilla – Bug 755954
Crash when accessing Gtk.Application.add_window()
Last modified: 2015-10-01 18:24:48 UTC
Created attachment 312522 [details] backtrace from the program above run in python 3 under gdb This simple python code crashes both python2 and python3: from gi.repository import Gtk app = Gtk.Application() window = Gtk.ApplicationWindow() app.add_window(window) Version information (Fedora 22): python-2.7.10-8.fc22.x86_64 python3-3.4.2-6.fc22.x86_64 glib2-2.44.1-2.fc22.x86_64 gtk3-3.16.7-1.fc22.x86_64 gobject-introspection-1.44.0-1.fc22.x86_64 pygobject2-2.28.6-13.fc22.x86_64 pygobject3-3.16.2-1.fc22.x86_64 python3-gobject-3.16.2-1.fc22.x86_64
That is not how GtkApplication is supposed to be used. Adding windows is expected to happen during or after ::startup, not just out of the blue.
+ Trace 235541
The implementation is created inside the startup vfunc(), which is called once the application started running. The proper way to create application windows is to connect/override the activate signal, and add windows there. We could add an assertion or a critical warning there, but it's not something Python is going to pick up anyway.
Created attachment 312523 [details] [review] app: Warn when trying to add windows on an inert instance Application windows can only be added after the application has been started.
Review of attachment 312523 [details] [review]: ::: gtk/gtkapplication.c @@ +1044,3 @@ + "GApplication::startup signal has been emitted."); + return; + } I think the G_UNLIKELY is unnecessary here... this is not something you're going to do in a tight loop. But the warning is a nice idea - there's probably more GtkApplication API that should have this.
(In reply to Matthias Clasen from comment #4) > Review of attachment 312523 [details] [review] [review]: > > ::: gtk/gtkapplication.c > @@ +1044,3 @@ > + "GApplication::startup signal has been emitted."); > + return; > + } > > I think the G_UNLIKELY is unnecessary here... this is not something you're > going to do in a tight loop. True. Will fix that before pushing. I'll also use g_application_get_is_registered(), since that's what we use already. > But the warning is a nice idea - there's probably more GtkApplication API > that should have this. We have various: g_return_if_fail (g_application_get_is_registered (… here and there, but obviously that does not tell you much about why the method failed — and there's the pesky issue of g_return_* macros being optionally disabled. We should probably use an actual warning instead, like we do inside GApplication to tell you to connect/override activate.
Created attachment 312524 [details] [review] app: Warn when trying to add windows on an inert instance Application windows can only be added after the application has been started.
Attachment 312524 [details] pushed as 707a071 - app: Warn when trying to add windows on an inert instance