Skip to content

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

@KingRainbow44

Description

@KingRainbow44

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions