rfd icon indicating copy to clipboard operation
rfd copied to clipboard

win: Repeated use of file dialog in asynchronous context causes access violation

Open KingRainbow44 opened this issue 1 month ago • 1 comments

I have a CLI tool which runs a prompt loop in an asynchronous Tokio context.

/// This gets called from `async main()`.
pub async fn prompt_loop() -> anyhow::Result<()> {
    loop {
        let selection = Select::with_theme(&*THEME)
            .with_prompt(...)
            .items(MenuOption::options())
            .default(0)
            .interact_opt()?;
        clearscreen::clear()?;

        match MenuOption::from_index(selection) {
            // ...
            Some(MenuOption::ImportSet) => import().await?,
            // ...
            _ => {}
        }
    }
}

async fn import() -> anyhow::Result<()> {
    info!("Select a folder of JSON files to continue...");

    let directory = FileDialog::new()
        .set_title("Select a folder of JSON files to import")
        .pick_folder()
        .ok_or_else(|| anyhow::anyhow!("No directory selected"))?;
    info!("Selected directory: {}", directory.display());

    // ...

    Ok(())
}

With this loop, I can access the file dialog once, but attempting to opening it again prints a cryptic:

10000 46000000
error: process didn't exit successfully: `executable.exe` (exit code: 0xc0000005, STATUS_ACCESS_VIOLATION)

which is thrown when calling let directory = FileDialog::new().

KingRainbow44 avatar Nov 25 '25 01:11 KingRainbow44

Does this reproduce the segfault? For me it does not (with tokio with full feature flag).

#[tokio::main]
async fn main() {
    loop {
        import().await;
    }
}

async fn import() {
    FileDialog::new().set_title("abc").pick_folder();
}

PolyMeilex avatar Dec 05 '25 21:12 PolyMeilex