iced icon indicating copy to clipboard operation
iced copied to clipboard

Application segfaults when exiting without first closing windows

Open Marlstar opened this issue 7 months ago • 10 comments

Is your issue REALLY a bug?

  • [x] My issue is indeed a bug!
  • [x] I am not crazy! I will not fill out this form just to ask a question or request a feature. Pinky promise.

Is there an existing issue for this?

  • [x] I have searched the existing issues.

Is this issue related to iced?

  • [x] My hardware is compatible and my graphics drivers are up-to-date.

What happened?

When using the iced::exit() Task with an active window open, the application closes the open window, hangs briefly, then segfaults. However, if window::close is called first such that there are no open windows, the application exits normally. As a byproduct of this behaviour, closing the window through the desktop environment/window manager leads to a successful exit as there are no windows left open when the program exits.

What is the expected behavior?

The application should close all open windows (as it does) and exit successfully (without segfaulting).

Version

master

Operating System

Linux

Do you have any log output?

# Using `iced::exit()`
$ cargo run 2>/dev/null
[1]    832223 segmentation fault (core dumped)  cargo run 2> /dev/null

# Using `iced::window::get_latest().and_then(iced::window::close).chain(iced::exit())`
$ cargo run 2>/dev/null
(no output)

Marlstar avatar Jun 07 '25 06:06 Marlstar

Do you have an example for this? The exit example in the examples dir works fine. Currious where your problem arises from?

13r0ck avatar Jun 11 '25 23:06 13r0ck

Hello! I've made a super simple program that reproduces the issue:

fn main() -> iced::Result {
    iced::run(update, view)
}

fn view(_: &usize) -> iced::Element<Message> {
    iced::Element::new(
        iced::widget::button("Exit")
            .on_press(Message::Exit)
    )
}

fn update(_: &mut usize, msg: Message) -> iced::Task<Message> {
    match msg {
        Message::Exit => iced::exit(),
    }
}

#[derive(Debug, Clone)]
enum Message {
    Exit,
}

Command-line:

$ cargo run 2>/dev/null
[1]    401840 segmentation fault (core dumped)  cargo run 2> /dev/null

Marlstar avatar Jun 12 '25 02:06 Marlstar

The reason that the exit example has no issue is because it does use the window::get_latest().and_then(window::close) as I specified above. See below: https://github.com/iced-rs/iced/blob/89f480bdae951a31944302777b759661ec3c3e83/examples/exit/src/main.rs#L23

Marlstar avatar Jun 12 '25 02:06 Marlstar

I kinda feel like exit is only meant for daemons that have already closed all of their windows

pml68 avatar Jun 12 '25 06:06 pml68

While this makes sense, the exit task does close the windows anyway (whether intentionally or not). While I'm not sure as to the complexity of implementation, I think it would make sense to automatically close all the windows before actually exiting. Alternatively, it could be documented on the exit task that it is intended to be called only when no windows are open (e.g., a daemon).

Marlstar avatar Jun 12 '25 06:06 Marlstar

I think it's a matter of documentation. Maybe you could ask Hector on the DC server?

pml68 avatar Jun 12 '25 07:06 pml68

I think it's fair to expect a library to not segfault, or if the API requires closing all windows first, then maybe the exit task should return an error if so.

Anyway, I would like to help with the core here, but @Marlstar your example works for me! 😆 Maybe this is related to winit for your specific system? What linux distro are you running? Is is x86?

13r0ck avatar Jun 12 '25 17:06 13r0ck

Hmm, that is interesting. I am running 64 bit fedora 42 on Wayland/hyprland. Device is a Dell XPS 15 9510. Using nouveau drivers for NVIDIA gpu. Using the wild linker (but it also happened with mold iirc). Latest rust stable unknown-linux-gnu toolchain.

I can't think of any other key details off the top of my head but let me know if there are any more important ones.

Marlstar avatar Jun 12 '25 22:06 Marlstar

I also went ahead and tried your example on latest master (commit 89f480b). It did not error for me in any way, exiting normally with a return code of 0.

64 bit Arch /w X.org (dwm), default mesa drivers and an AMD RX 7700 XT. mold linker, x86_64-unknown-linux-gnu target on Rust 1.89.0-nightly (414482f6a 2025-05-13)

pml68 avatar Jun 12 '25 22:06 pml68

Just tried using nightly, on same latest master commit. My nightly toolchain is currently 1.88.0-nightly (cannot update it right now due to network issues). Same issue.

Marlstar avatar Jun 16 '25 01:06 Marlstar

I'm also getting a segfault on my machine when executing the iced::exit() task. I'm on an AARCH64 processor running WSL2.

marcusklaas avatar Aug 19 '25 11:08 marcusklaas

Getting a segfault too when closing the window. With the button in the corner, with iced::exit() and with return window::get_latest().and_then(window::close);.

iced = { version = "0.13.1", features = ["tokio", "wgpu"] }

Gnome 48, wayland, nvidia proprietary drivers. Removing wgpu from the features did not change the behavior, still crashes on close with SIGSEGV.

fn update(_: &mut (), _: ()) -> Task<()> { Task::none() }
fn view(_: &()) -> Element<()> { row![].into() }
application("Iced Hello World", update, view).run()

and then just close the window.

WhiteBlackGoose avatar Sep 20 '25 10:09 WhiteBlackGoose

Try master, I think I fixed this in https://github.com/iced-rs/iced/commit/355f0e09218a8c9c1bed08b04201d32030a4150c.

hecrj avatar Sep 20 '25 11:09 hecrj