PolyMeilex / rfd

Rusty File Dialog
MIT License
524 stars 60 forks source link

Save Dialog locks up when selecting an Existing File and clicking the Save button. (Windows 10) #164

Open Munjen opened 7 months ago

Munjen commented 7 months ago

Hello! I posted this issue to the slint repository but now after testing with Linux it seems more likely that the problem is in the RFD crate. I'm using the rfd crate to create a Save Dialog for my slint application on Windows 10. The Save Dialog works perfectly except when I select an existing file and click the save button (on the save dialog). The Save Dialog stays open and both the Slint UI and the Save Dialog lock up refusing to respond to buttons and controls. Nothing can stop the process except 'kill terminal' in VSCode.

A simple test project with just the rfd crate ...and Save Dialog works fine. The overwrite file message box opens and the Save Dialog closes if user responds to 'Overwrite existing file?' with 'Yes' as expected!

I put the rfd code inside a closure that runs when a slint save button is pressed I'm not 100% sure if this is some bug in slint, rfd or am I doing something incorrectly?

Today I tried compiling on Linux Mint 21.2, Cinnamon v5.8.4, Linux Kernel: 5.15.0-88-generic. On Linux everything works fine, No issues at all! I will post this issue to RFD git as well because now it seems more likely that the problem is coming from the rfd crate.

main_window.on_save_pressed(move |x, y| {
        let file = match save_dialog() {
            Some(s) => s,
            None => return,
        };

       //... doing stuff with the returned string...
       //... doing stuff with x, y parameters...
       //... doing stuff with a weak pointer to main_window...
});

use rfd::FileDialog;
fn save_dialog() -> Option<String> {
    let file = FileDialog::new()
        .set_file_name("Output.exr")
        .add_filter("Open EXR", &["exr"])
        .set_title("Save As 32bit EXR")
        .save_file();

    match file {
        Some(f) => Some(f.into_os_string().into_string().unwrap()),
        None => None,
    }
}
Munjen commented 6 months ago

With my limited skills I tried to run in debug mode with VSCode and the farthest I can trace it are these two functions: rfd-0.12.1\src\backend\win_cid\utils.rs --> init_com function on line 28. calls rfd-0.12.1\src\backend\win_cid\file_dialog.rs --> line 106: impl FileSaveDialogImpl for FileDialog --> line 111: dialog.show()?;

The dialog opens on line 111 and becomes interactive. But after pressing save to overwrite an existing file everything freezes. Probably it is some unsafe interface with windows API or something causing the problem?

Sandvoxel commented 3 months ago

Ill add that this is also a issue on windows 11. It seems almost random when it decides to do it as I have gotten it to work only to relaunch and have it not work.

Sandvoxel commented 3 months ago

@Munjen I did some experimentation an it seems like this bug was introduced on 0.13.0 as 0.12.1 dose not have the issue

PolyMeilex commented 3 months ago

There was no windows backend changes bettwen those versions: https://github.com/PolyMeilex/rfd/compare/0.12.1...0.13.0 :smile:

The only thing that could affect anything windows related is the cargo lock changes, but I don't see anything obvious in there.

Sandvoxel commented 3 months ago

There was no windows backend changes bettwen those versions: 0.12.1...0.13.0 😄

The only thing that could affect anything windows related is the cargo lock changes, but I don't see anything obvious in there.

My mistake I just went back and tested again and it seems to go back to 0.11.4 (Just where I happened to stop). Unsure what is causing the lockup.