From 77c98ee813ada46f0d6a81cf000c0b19d5b77c08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mariusz=20Kry=C5=84ski?= Date: Sun, 30 Aug 2020 02:16:46 +0200 Subject: [PATCH] Fix deadlock in hot asset reloading (#375) (#376) --- crates/bevy_asset/src/asset_server.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/crates/bevy_asset/src/asset_server.rs b/crates/bevy_asset/src/asset_server.rs index fa7f7139eed32..350a832cea439 100644 --- a/crates/bevy_asset/src/asset_server.rs +++ b/crates/bevy_asset/src/asset_server.rs @@ -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,