I was learning gtk and made a tiny little application :
use gtk::{Application, ApplicationWindow, Orientation, Button};
use gtk::prelude::*;
#[macro_use]
extern crate gtk;
fn main() {
let app = Application::new(Some("co.telnobynoyator.expmath"), Default::default());
app.connect_activate(|app| {
let window = ApplicationWindow::new(app);
window.set_title(Some("ExpMath"));
let mut main_box = gtk::Box::new(Orientation::Vertical, 0);
let mut toolbar = gtk::Box::new(Orientation::Horizontal, 0);
toolbar.set_css_classes(&["toolbar"]);
toolbar.append(&Button::with_label("File"));
toolbar.append(&Button::with_label("Edit"));
toolbar.append(&Button::with_label("View"));
toolbar.append(&Button::with_label("Help"));
main_box.append(&toolbar);
main_box.append(&Button::with_label("Test"));
window.set_child(Some(&main_box));
window.present();
});
app.run();
}
And sometimes (not all the time) when I close my application window, the whole shell becomes unresponsive (GNOME Shell 40.3).
I’m probably doing something wrong since my application is the only application that crashes the system…
Any advice ?
Thanks in advance !
EDIT: Last time it happened after I resized my window but I don’t know if that’s related…
EDIT : It happened without resizing but this time I moved the window.
Also, I can’t access my tty devices with control + alt + f… after the freeze.
Are you sure that works reliable? In other rust examples from https://gtk.org/ or Hello World! - GUI development with Rust and GTK 4 I generally see use of top level functions only. Do that examples crash for you too? And maybe use a recent GTK4 and Rust-GTK4 version. Do you run your program on Windows, FreeBSD or MacOS? When on Linux, maybe run it with valgrind.
I’ll try using a top level function instead, I’ll tell you how it goes. I’m using the latest version of everything, including the gtk libraries and crates. I’m running my program on Linux, I’ll try running it with valgrind, I’ll tell you how it goes as well.
The thing is :
in this case closures and top level functions should compile to the exact same thing.
this shouldn’t affect my entire system, should it ?
This should just not happen, unless something is not really terminating and it’s basically running a DoS on your system. Are you sure that your application actually terminates?
You could try and debug it via strace, or running it under GDB and interrupting the flow of the process when it starts spinning.
I basically kept running the program and closing it until it happened. At that point I couldn’t do anything : couldn’t move my mouse, switch to a tty device, interact with any window, etc… I had to forcefully shutdown my pc by holding the power button.
EDIT :
I’m seeing “process exited normally” on the very bottom, yet it still crashed. So (I guess) that’s not it ?
So my guess is that it is not a Rust issue, but related to your GTK4 install.
Have you installed GTK4 from git sources, or is it from your Linux distribution?
Do you use Shell-Extensions? I heard that people doing that had crashes like you describe in the past.
What you may do:
Test other GTK4 tools like gtk4-demo
Make a plain C version of your program and test that
Remove parts of your Rust program and see if crash vanishes
Run your program with valgrind
I just made a Nim version and tested it, works fine:
import gintro/[gtk4, gobject, gio]
from strutils import split
proc activate(app: gtk4.Application) =
let window = newApplicationWindow(app)
window.setTitle("ExpMath")
let mainBox = newBox(Orientation.vertical)
let toolbar = newBox(Orientation.horizontal)
toolbar.setCssClasses("toolbar")
for l in "File Edit View Help".split:
toolbar.append(newButton(l))
mainBox.append(toolbar)
mainBox.append(newButton("Test"))
window.setChild(mainBox)
window.present
proc main =
let app = newApplication("co.telnobynoyator.expmath")
app.connect("activate", activate)
let status = app.run
quit(status)
main()
Only the default ones I had when I installed my distro : “AppIndicator and KStatusNotifierItem Support”, “Dash to Dock”, “Pamac updates indicator” (I switched to Manjaro since my last thread), “User themes”.
Afaik my app is the only thing that does this crash, but I’ll try with gtk4-demo (maybe the other apps I have all use gtk3 and not 4)
It was already crashing when there was just a window
You don’t need to mention people that are in the thread.
At this point, I’m wondering if it’s an issue of your Linux distribution or your drivers. It seems you’re using Nouveau (the free drivers for nVidia GPUs), and from your logs I see a bunch of Xwayland crashes and Shell issues.
I think this has really nothing to do with GTK4, except that GTK4 is using GL, and after a while that messes up your driver state. I’d say “try with the nVidia binary driver”, even though that forces an X11 session.