I’m currently building my first GTK app in Rust and it’s been great so far but I’ve run into a problem. I have a gtk::Entry
pre-populated with text being presented in a gtk::Window
modal. But when it launches if I hit the left or right arrow key it will usually (but not always) crash with the following error:
Pango-CRITICAL **: 18:36:30.302: _pango_layout_get_iter: assertion ‘PANGO_IS_LAYOUT (layout)’ failed
The odd thing is that if the gtk::Entry
is not pre-populated with text the crash won’t happen.
I’ve extracted out the minimal code to reproduce this below:
use gtk::glib;
use gtk::prelude::*;
fn main() -> glib::ExitCode {
let app = gtk::Application::builder()
.application_id("com.example.pango_is_layout_error")
.build();
app.connect_activate(|app| {
let window = gtk::ApplicationWindow::new(app);
let modal = gtk::Window::builder()
.transient_for(&window)
.modal(true)
.build();
let text = "Hello there!";
let entry = gtk::Entry::builder().text(text).build();
let child = gtk::Box::new(gtk::Orientation::Vertical, 0);
child.append(&entry);
modal.set_child(Some(&child));
window.present();
modal.present();
});
app.run()
}
And here’s my Cargo file:
[package]
name = "gtk-pango-is-layout-error"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
gtk = { version = "0.6.1", package = "gtk4", features = ["v4_6"] }
Anyone have any idea what could be causing this or how to debug it?
EDIT: I’ve found a workaround for this by inserting the following code in the app.connect_activate
callback.
if let Some(settings) = gtk::Settings::default() {
settings.set_gtk_entry_select_on_focus(false);
}
This deselects the entry text initially which appears to mitigate the crashing issue but I would prefer to resolve this issue without having to utilize a hack like this.