GNOME Bugzilla – Bug 681323
Segfault from Application::run(Window&) with ApplicationWindow
Last modified: 2012-08-29 18:13:32 UTC
http://developer.gnome.org/gtkmm-tutorial/stable/sec-basics-simple-example.html.en The initial code sample, as well as the source proper, makes the window variable an instance of Gtk::ApplicationWindow. Further down the document, during the synopsis of the code, the same variable is referenced as an instance of Gtk:Window. While ApplicationWindow inherits from Window, it shouldn't be assumed that readers have previous knowledge of this and can interchange the two on-the-fly.
Created attachment 221301 [details] [review] patch:Application: Don't call add_window() before the app is registered (gtkmm) There are other discrepancies between code and description in the "Basics" chapter, "Simple Example" section. E:g. the window is said to be 200 x 200 pixels, but no specific size is requested in the code. And the description says "the next two lines of code" where there is only one line. I can fix all that, but there is a more serious bug in the Gtk::Application class, which makes the examples/book/base program print Gtk:ERROR:gtkapplicationwindow.c:847:gtk_application_window_unpublish: assertion failed: (window->priv->session != NULL) Program received signal SIGABRT, Aborted. when the window is closed. That's because gtk_application_add_window() is called before the application is registered and gtk_application_startup() is called. The attached bug fixes that. The bug changes the name of a Gtk::Application member function. I assume that it's OK to do that, since it's a private function. I am right?
The patch in comment 1 is not good enough. If two examples/book/base are started, the second one stops immediately. Without the patch it does not stop, but its window is not shown. If several instances of a program are started, Gtk::Application:: on_activate_show_main_window() is called only for the first instance. I don't yet know how to fix this bug.
(In reply to comment #1) > Created an attachment (id=221301) [details] [review] > patch:Application: Don't call add_window() before the app is registered (gtkmm) > > There are other discrepancies between code and description in the "Basics" > chapter, "Simple Example" section. E:g. the window is said to be 200 x 200 > pixels, but no specific size is requested in the code. And the description > says "the next two lines of code" where there is only one line. > > I can fix all that, but there is a more serious bug in the Gtk::Application > class, which makes the examples/book/base program print > > Gtk:ERROR:gtkapplicationwindow.c:847:gtk_application_window_unpublish: > assertion failed: (window->priv->session != NULL) > Program received signal SIGABRT, Aborted. > > when the window is closed. That's because gtk_application_add_window() is > called before the application is registered and gtk_application_startup() is > called. The attached bug fixes that. > > The bug changes the name of a Gtk::Application member function. I assume that > it's OK to do that, since it's a private function. I am right? This whole bit points out the underlying problem that I have. The documentation puts would-be GTKMM developers in an awkward situation where the code presented to them is quite literally failing. Granted that we could expect readers should have a bit more than a general knowledge of C++, some don't and learn from the code samples instead. While I was personally working through the code on the page in question, when I'd changed the program to use Gtk::Window, it worked fine. I'm sure that the entire scope of this problem is well beyond me (at least at this point). My argument here is that documentation/tutorials are effectively the public representation of any API. Regardless of the current technical issues surrounding Gtk::ApplicationWindow and it's cohorts, it being in the page in question is causing the source not to run properly AND is also conflicting with the use of Gtk::Window further down the page. Although Gtk::Window may not be the preferred method of referencing a window now (is that the case?), why not have it in the documentation until the kinks in other classes are worked out? In that way, _the sample code actually works._ This isn't really a "none-the-wiser" argument either. It's simply trying to make sure that GTKMM is being represented by documentation that isn't going to require you to rip your hair out just to get a rudimentary sample working. My suggestion is to simply change the sample source to something that works so long as the classes aren't deprecated and it cleans up the class usage conflicts, then we can worry about the technical snafus of Gtk::ApplicationWindow without putting new devs in the line of fire. The clear benefit here is that they're getting to use source that doesn't fail at run-time for reasons that aren't their own.
I've updated the Basics - Simple Example section in the tutorial and replaced Gtk::ApplicationWindow by Gtk::Window in examples/book/base/base.cc. http://git.gnome.org/browse/gtkmm-documentation/commit/?id=400a2250853aefcadb0f52cb2896392c397e9f11 This was the only example in the tutorial where Window had previously been replaced by ApplicationWindow. (There are more such examples in examples/book/ application, but they are not shown in the tutorial.) We'd better stick to Window in the tutorial until ApplicationWindow does not cause crashes. (In reply to comment #2) > The patch in comment 1 is not good enough. Perhaps it is good enough after all. More than one application instance can be started, if flags = Gio::APPLICATION_NON_UNIQUE is added to the call to Gtk::Application::create(). Is this how it's supposed to be? Only one instance at a time can be running, if the Gtk::Application is created without Gio::APPLICATION_NON_UNIQUE? I consider the tutorial fixed, but I keep this bug open until Gtk::Application::run(Window&) has been fixed so it can be used together with Gtk::ApplicationWindow. I'm just not sure if my patch in comment 1 is the right way to fix it. Does anybody know?
(In reply to comment #4) > I've updated the Basics - Simple Example section in the tutorial and replaced > Gtk::ApplicationWindow by Gtk::Window in examples/book/base/base.cc. > > http://git.gnome.org/browse/gtkmm-documentation/commit/?id=400a2250853aefcadb0f52cb2896392c397e9f11 Thank you for that. With regard to comment #1... I haven't been able to make that error occur. Instead, when using Gtk::ApplicationWindow with Gtk::Application::run, I get this: GLib-GIO-CRITICAL **: g_application_list_actions: assertion `application->priv->is_registered' failed which is reported as a segfault. I modified the source from examples/book/base with the following lines: if(!app->is_registered()) { app->register_application(); } and left in the Gtk::ApplicationWindow instance. Surprisingly, the program compiled and executed without an issue. Could this hint toward the problem or is this something else that's entirely different?
(In reply to comment #5) > I haven't been able to make that error occur. Instead, when using > Gtk::ApplicationWindow with Gtk::Application::run, I get this: > > GLib-GIO-CRITICAL **: g_application_list_actions: assertion > `application->priv->is_registered' failed That's probably because you don't use the latest version of gtkmm from the git repository. Gtk::Application::run(Window&) was modified 2012-06-12, but that modification is so far only available in the unstable gtkmm version 3.5.6. I think the patch in comment 1 is an acceptable solution, but I hope it can be confirmed by someone who is more used to the GtkApplication and GApplication classes than I am. There might be a better way.
I've looked at the example program in gtk+ (gtk+/demos, gtk+/examples, gtk+/tests). They create a window and add it to the application in GApplication's "activate" signal handler. Some example programs must be modified, because it must be possible to run more than one instance at a time. examples/book/clipboard/ideal/main.cc examples/book/clipboard/simple/main.cc examples/book/socket/plug.cc, socket.cc plug and socket shall not have the same application id. I will take a break from Gnome now. I will fix this bug when I'm back, if no one else has done it by then.
If all the simple documentation bugs have been fixed, shouldn't this bug be retitled, or a separate bug opened about the Gtk::Application problems?
Yes, you're right. I've changed the title. That's the easiest alternative, but perhaps it would have been better to split this bug into 3 bug reports. I've pushed the patch in comment 1 to gtkmm (with some slightly modified comments in application.ccg), http://git.gnome.org/browse/gtkmm/commit/?id=e05d9666464e90c8e6cf347d7ef63680e0a44b2c and a patch to gtkmm-documentation, which makes it possible to run the clipboard and socket examples as intended, http://git.gnome.org/browse/gtkmm-documentation/commit/?id=12b053a292ae872da7eaefc0e28ef9d16132ae39 With these patches this bug is fixed.