diff --git a/crates/eframe/src/native/file_storage.rs b/crates/eframe/src/native/file_storage.rs index 1b4c254c2c2..6b059e81799 100644 --- a/crates/eframe/src/native/file_storage.rs +++ b/crates/eframe/src/native/file_storage.rs @@ -1,5 +1,6 @@ use std::{ collections::HashMap, + io::Write, path::{Path, PathBuf}, }; @@ -126,10 +127,13 @@ fn save_to_disk(file_path: &PathBuf, kv: &HashMap) { match std::fs::File::create(file_path) { Ok(file) => { + let mut writer = std::io::BufWriter::new(file); let config = Default::default(); - if let Err(err) = ron::ser::to_writer_pretty(file, &kv, config) { - log::warn!("Failed to serialize app state: {err}"); + if let Err(err) = ron::ser::to_writer_pretty(&mut writer, &kv, config) + .and_then(|_| writer.flush().map_err(|err| err.into())) + { + log::warn!("Failed to serialize app state: {}", err); } else { log::trace!("Persisted to {:?}", file_path); }