rfd
rfd copied to clipboard
win: Repeated use of file dialog in asynchronous context causes access violation
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().
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();
}