sornas / lingon

1 stars 0 forks source link

File system race condition when reloading assets #41

Closed sornas closed 3 years ago

sornas commented 3 years ago

I got this just now while re-loading a file. The asset loaded fine when I restarted.

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Custom { kind: UnexpectedEof, error: "failed to fill whole buffer" }', src/asset/audio.rs:55:74
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

We can either check if the file is done being written to in some way, or mark the file as "actually, try to load it again next frame" if the data parsing fails.

sornas commented 3 years ago

The line in question was

        let (header, data) = wav::read(&mut std::io::Cursor::new(bytes)).unwrap();
FredTheDino commented 3 years ago

I suspect the problem is the OS writing to the file continousely, and updating the timestamp. So we could solve it for that special case - but all new assettypes we add will have the same problem.

A more general solution would be to only load assets if they are older than 1s, or wait 20 frames to reload the data once. Adding a delay before we delegate to the actual loading.