Skip to content

Commit

Permalink
Fix deadlock in hot asset reloading (bevyengine#375) (bevyengine#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrk-its committed Oct 6, 2020
1 parent 337b526 commit 77c98ee
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions crates/bevy_asset/src/asset_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,20 @@ impl AssetServer {
use notify::event::{Event, EventKind, ModifyKind};
let mut changed = HashSet::default();

while let Some(filesystem_watcher) = asset_server.filesystem_watcher.read().as_ref() {
let result = match filesystem_watcher.receiver.try_recv() {
Ok(result) => result,
Err(TryRecvError::Empty) => {
loop {
let result = {
let rwlock_guard = asset_server.filesystem_watcher.read();
if let Some(filesystem_watcher) = rwlock_guard.as_ref() {
filesystem_watcher.receiver.try_recv()
} else {
break;
}
};
let event = match result {
Ok(result) => result.unwrap(),
Err(TryRecvError::Empty) => break,
Err(TryRecvError::Disconnected) => panic!("FilesystemWatcher disconnected"),
};

let event = result.unwrap();
if let Event {
kind: EventKind::Modify(ModifyKind::Data(_)),
paths,
Expand Down

0 comments on commit 77c98ee

Please sign in to comment.