Entire shell / system crashes when I close the application I'm developing

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.

You are using that in place closure notation

app.connect_activate(|app| {

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 ?
1 Like

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.

So I ran it under GDB and this is the content of the gdb.txt log file

Starting program: /home/teln0/CLionProjects/expmath/target/debug/expmath 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[New Thread 0x7ffff3842640 (LWP 4155)]
[New Thread 0x7ffff3041640 (LWP 4156)]
[New Thread 0x7ffff2558640 (LWP 4157)]
[New Thread 0x7ffff1d1d640 (LWP 4158)]
[Thread 0x7ffff2558640 (LWP 4157) exited]
[New Thread 0x7ffff2558640 (LWP 4159)]
[New Thread 0x7ffff0b78640 (LWP 4160)]
[New Thread 0x7fffe2571640 (LWP 4161)]
[New Thread 0x7fffe1d70640 (LWP 4162)]
[New Thread 0x7fffe156f640 (LWP 4163)]
[New Thread 0x7fffd5d54640 (LWP 4164)]
[New Thread 0x7fffd5553640 (LWP 4165)]
[New Thread 0x7fffd4d52640 (LWP 4166)]
[New Thread 0x7fffb7fff640 (LWP 4167)]
[Thread 0x7fffd4d52640 (LWP 4166) exited]
[Thread 0x7fffb7fff640 (LWP 4167) exited]
[New Thread 0x7fffb7fff640 (LWP 4168)]
[New Thread 0x7fffd4d52640 (LWP 4169)]
[Thread 0x7fffb7fff640 (LWP 4168) exited]
[Thread 0x7fffd4d52640 (LWP 4169) exited]
[Thread 0x7fffd5d54640 (LWP 4164) exited]
[Thread 0x7fffd5553640 (LWP 4165) exited]
[Thread 0x7fffe156f640 (LWP 4163) exited]
[Thread 0x7fffe1d70640 (LWP 4162) exited]
[Thread 0x7fffe2571640 (LWP 4161) exited]
[Thread 0x7ffff0b78640 (LWP 4160) exited]
[Thread 0x7ffff1d1d640 (LWP 4158) exited]
[Thread 0x7ffff3041640 (LWP 4156) exited]
[Thread 0x7ffff3842640 (LWP 4155) exited]
[Thread 0x7ffff3845980 (LWP 4151) exited]
[Inferior 1 (process 4151) exited normally]
Starting program: /home/teln0/CLionProjects/expmath/target/debug/expmath 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[New Thread 0x7ffff3842640 (LWP 4176)]
[New Thread 0x7ffff3041640 (LWP 4177)]
[New Thread 0x7ffff2558640 (LWP 4178)]
[New Thread 0x7ffff1d1d640 (LWP 4179)]
[Thread 0x7ffff2558640 (LWP 4178) exited]
[New Thread 0x7ffff2558640 (LWP 4180)]
[New Thread 0x7ffff0b7c640 (LWP 4181)]
[New Thread 0x7fffe2571640 (LWP 4182)]
[New Thread 0x7fffe1d70640 (LWP 4183)]
[New Thread 0x7fffe156f640 (LWP 4184)]
[New Thread 0x7fffd5d54640 (LWP 4185)]
[New Thread 0x7fffd5553640 (LWP 4186)]
[New Thread 0x7fffd4d52640 (LWP 4187)]
[New Thread 0x7fffb7fff640 (LWP 4188)]
[Thread 0x7fffd4d52640 (LWP 4187) exited]
[Thread 0x7fffb7fff640 (LWP 4188) exited]
[New Thread 0x7fffb7fff640 (LWP 4189)]
[New Thread 0x7fffd4d52640 (LWP 4190)]
[Thread 0x7fffb7fff640 (LWP 4189) exited]
[Thread 0x7fffd4d52640 (LWP 4190) exited]
[Thread 0x7ffff2558640 (LWP 4180) exited]
[Thread 0x7fffd5553640 (LWP 4186) exited]
[Thread 0x7fffe156f640 (LWP 4184) exited]
[Thread 0x7fffe1d70640 (LWP 4183) exited]
[Thread 0x7fffe2571640 (LWP 4182) exited]
[Thread 0x7ffff0b7c640 (LWP 4181) exited]
[Thread 0x7fffd5d54640 (LWP 4185) exited]
[Thread 0x7ffff1d1d640 (LWP 4179) exited]
[Thread 0x7ffff3041640 (LWP 4177) exited]
[Thread 0x7ffff3842640 (LWP 4176) exited]
[Inferior 1 (process 4175) exited normally]
Starting program: /home/teln0/CLionProjects/expmath/target/debug/expmath 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[New Thread 0x7ffff3842640 (LWP 4194)]
[New Thread 0x7ffff3041640 (LWP 4195)]
[New Thread 0x7ffff2558640 (LWP 4196)]
[New Thread 0x7ffff1d1d640 (LWP 4197)]
[Thread 0x7ffff2558640 (LWP 4196) exited]
[New Thread 0x7ffff2558640 (LWP 4198)]
[New Thread 0x7ffff0b7c640 (LWP 4199)]
[New Thread 0x7fffe2571640 (LWP 4200)]
[New Thread 0x7fffe1d70640 (LWP 4201)]
[New Thread 0x7fffe156f640 (LWP 4202)]
[New Thread 0x7fffd5d54640 (LWP 4203)]
[New Thread 0x7fffd5553640 (LWP 4204)]
[New Thread 0x7fffd4d52640 (LWP 4205)]
[New Thread 0x7fffb7fff640 (LWP 4206)]
[Thread 0x7fffd4d52640 (LWP 4205) exited]
[Thread 0x7fffb7fff640 (LWP 4206) exited]
[New Thread 0x7fffb7fff640 (LWP 4207)]
[New Thread 0x7fffd4d52640 (LWP 4208)]
[Thread 0x7fffb7fff640 (LWP 4207) exited]
[Thread 0x7fffd4d52640 (LWP 4208) exited]
[Thread 0x7fffd5d54640 (LWP 4203) exited]
[Thread 0x7fffd5553640 (LWP 4204) exited]
[Thread 0x7fffe156f640 (LWP 4202) exited]
[Thread 0x7fffe1d70640 (LWP 4201) exited]
[Thread 0x7fffe2571640 (LWP 4200) exited]
[Thread 0x7ffff0b7c640 (LWP 4199) exited]
[Thread 0x7ffff2558640 (LWP 4198) exited]
[Thread 0x7ffff1d1d640 (LWP 4197) exited]
[Thread 0x7ffff3041640 (LWP 4195) exited]
[Thread 0x7ffff3842640 (LWP 4194) exited]
[Inferior 1 (process 4193) exited normally]
Starting program: /home/teln0/CLionProjects/expmath/target/debug/expmath 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[New Thread 0x7ffff3842640 (LWP 4215)]
[New Thread 0x7ffff3041640 (LWP 4216)]
[New Thread 0x7ffff2558640 (LWP 4217)]
[New Thread 0x7ffff1d1d640 (LWP 4218)]
[Thread 0x7ffff2558640 (LWP 4217) exited]
[New Thread 0x7ffff2558640 (LWP 4219)]
[New Thread 0x7ffff0b77640 (LWP 4220)]
[New Thread 0x7fffe2571640 (LWP 4221)]
[New Thread 0x7fffe1d70640 (LWP 4222)]
[New Thread 0x7fffe156f640 (LWP 4223)]
[New Thread 0x7fffd5d54640 (LWP 4224)]
[New Thread 0x7fffd5553640 (LWP 4225)]
[New Thread 0x7fffd4d52640 (LWP 4226)]
[New Thread 0x7fffb7fff640 (LWP 4227)]
[Thread 0x7fffd4d52640 (LWP 4226) exited]
[Thread 0x7fffb7fff640 (LWP 4227) exited]
[New Thread 0x7fffb7fff640 (LWP 4228)]
[New Thread 0x7fffd4d52640 (LWP 4229)]
[Thread 0x7fffb7fff640 (LWP 4228) exited]
[Thread 0x7fffd4d52640 (LWP 4229) exited]
[Thread 0x7fffd5553640 (LWP 4225) exited]
[Thread 0x7ffff2558640 (LWP 4219) exited]
[Thread 0x7fffe156f640 (LWP 4223) exited]
[Thread 0x7fffe1d70640 (LWP 4222) exited]
[Thread 0x7fffe2571640 (LWP 4221) exited]
[Thread 0x7ffff0b77640 (LWP 4220) exited]
[Thread 0x7fffd5d54640 (LWP 4224) exited]
[Thread 0x7ffff1d1d640 (LWP 4218) exited]
[Thread 0x7ffff3041640 (LWP 4216) exited]
[Thread 0x7ffff3842640 (LWP 4215) exited]
[Inferior 1 (process 4214) exited normally]
Starting program: /home/teln0/CLionProjects/expmath/target/debug/expmath 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[New Thread 0x7ffff3842640 (LWP 4232)]
[New Thread 0x7ffff3041640 (LWP 4233)]
[New Thread 0x7ffff2558640 (LWP 4234)]
[New Thread 0x7ffff1d1d640 (LWP 4235)]
[Thread 0x7ffff2558640 (LWP 4234) exited]
[New Thread 0x7ffff2558640 (LWP 4236)]
[New Thread 0x7ffff0b7c640 (LWP 4237)]
[New Thread 0x7fffe2571640 (LWP 4238)]
[New Thread 0x7fffe1d70640 (LWP 4239)]
[New Thread 0x7fffe156f640 (LWP 4240)]
[New Thread 0x7fffd5d54640 (LWP 4241)]
[New Thread 0x7fffd5553640 (LWP 4242)]
[New Thread 0x7fffd4d52640 (LWP 4243)]
[New Thread 0x7fffb7fff640 (LWP 4244)]
[Thread 0x7fffd4d52640 (LWP 4243) exited]
[Thread 0x7fffb7fff640 (LWP 4244) exited]
[New Thread 0x7fffb7fff640 (LWP 4245)]
[New Thread 0x7fffd4d52640 (LWP 4246)]
[Thread 0x7fffb7fff640 (LWP 4245) exited]
[Thread 0x7fffd4d52640 (LWP 4246) exited]
[Thread 0x7fffd5d54640 (LWP 4241) exited]
[Thread 0x7fffd5553640 (LWP 4242) exited]
[Thread 0x7fffe156f640 (LWP 4240) exited]
[Thread 0x7fffe1d70640 (LWP 4239) exited]
[Thread 0x7fffe2571640 (LWP 4238) exited]
[Thread 0x7ffff0b7c640 (LWP 4237) exited]
[Thread 0x7ffff2558640 (LWP 4236) exited]
[Thread 0x7ffff1d1d640 (LWP 4235) exited]
[Thread 0x7ffff3842640 (LWP 4232) exited]
[Thread 0x7ffff3845980 (LWP 4231) exited]
[Inferior 1 (process 4231) exited normally]

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 ?

Have you checked the journal?

Where is it ? Sorry I’m a bit new to this whole thing…

journalctl -f in your terminal.
Then do the same things that crashed your program – you will be able to view the journal live in your terminal.

Well -f (follow) won’t help much when the session is crashing… something like

journalctl --since "5 minutes ago"

Is probably more useful (once you’ve started a new session)

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()

5 minutes ago log - JustPaste.it Here is the “5 minutes ago” version
15 minutes ago - JustPaste.it Here is the “15 minutes ago” version

I hit the size limit of pastebin so I’ve decided to use this website

I installed the package for my distrubution

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

I’m not great at c but I’ll try

I’ll try that too

UPDATE : The crash also happened with gtk4-demo

@zbrown @ebassi (I though it may be important to also mention you two)

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.

1 Like

So I should try the proprietary driver ? Ok I’ll try…

I now have this :

Kernel driver in use: nvidia

when I run lspci.

I launched gtk4-demo a few times and it doesn’t seem to crash anymore.
I’ll try again a bit more but I think everything works now.

Thanks !

2 Likes