gtkmm-demo crash - Application::run(Window&) not a good idea anymore?
After some recent a11y commits in gtk4, I noticed that gtkmm-demo crashes immediately when you start it.
gtkmm-demo uses Application::run(Window& window, int argc, char** argv), which means it creates the window including its member widgets before calling run. For some widgets this is not OK anymore, here it crashes inside a Gtk::Box constructor.
The helloworld application from gtkmm-documentation, which uses the same run method, but only has a Gtk::Button, doesn't crash at startup, but it does crash at shutdown.
I guess that you are supposed to create the widgets in the activate signal handler, which means the convenience methods Application::run(Window&) and Application:run(Window& window, int argc, char** argv) are not really possible to use anymore.
I'm not sure if we need some new methods or just a new recommended way of writing the main function. Here's the main function from gtkmm-demo that crashes:
int main (int argc, char *argv[])
{
auto app = Gtk::Application::create();
DemoWindow window;
return app->run(window, argc, argv);
}
Here's a version that doesn't crash:
int main (int argc, char *argv[])
{
auto app = Gtk::Application::create();
Gtk::Window* window = nullptr;
app->signal_activate().connect([&]() {
window = new DemoWindow;
app->add_window(*window);
window->show();
});
app->signal_shutdown().connect([&]() {
delete window;
});
return app->run(argc, argv);
}