My Gtk-rs application crashes whenever I try calling the show_all() function.

In a simple application window, I have added a headerbar and a label. If I compile without adding the headerbar, the window works and shows the label as intended. However if I add the headerbar the window crashes.

use gio::prelude::*; use gtk::{ prelude::*, HeaderBarExt, GtkWindowExt }; fn gen_header_bar(subtitle: Option<String>) -> gtk::HeaderBar { let header_bar = gtk::HeaderBar::new(); header_bar.set_title(Some(crate::consts::APP_NAME)); header_bar.set_show_close_button(true); match subtitle { Some(subtitle) => { header_bar.set_subtitle(Some(&subtitle)); }, _ => { } } header_bar } pub fn build_application_window() -> Result<(), Box<dyn std::error::Error>> { let application = gtk::Application::new( Some(crate::consts::APP_ID), gio::ApplicationFlags::FLAGS_NONE, )?; application.connect_activate(move |app| { let window = gtk::ApplicationWindow::new(app); window.set_title(crate::consts::APP_NAME); window.set_default_size(32 * 10, 200); // golden ratio window.set_position(gtk::WindowPosition::Center); let header_bar = gen_header_bar(None); window.set_titlebar(Some(&header_bar)); window.add(&{ let label = gtk::Label::new(Some("Welcome!")); label }); window.show_all(); // crashes here }); application.run(&std::env::args().collect::<Vec<_>>()); Ok(()) }

What is causing this?