Skip to content

Commit

Permalink
Fix file_watcher feature hanging indefinitely (#10585)
Browse files Browse the repository at this point in the history
# Objective

Fix the `bevy_asset/file_watcher` feature in practice depending on
multithreading, while not informing the user of it.

**As I understand it** (I didn't check it), the file watcher feature
depends on spawning a concurrent thread to receive file update events
from the `notify-debouncer-full` crate. But if multithreading is
disabled, that thread will never have time to read the events and
consume them.

- Fixes #10573 


## Solution

Add a `compile_error!` causing compilation failure if `file_watcher` is
enabled while `multi-threaded` is disabled.

This is considered better than adding a dependency on `multi-threaded`
on the `file_watcher`, as (according to @mockersf) toggling on/off
`multi-threaded` has a non-zero chance of changing behavior. And we
shouldn't implicitly change behavior. A compilation failure prevents
compilation of code that is invalid, while informing the user of the
steps needed to fix it.
  • Loading branch information
nicopap authored Nov 20, 2023
1 parent ef50b3c commit 96444b2
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions crates/bevy_asset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ use bevy_log::error;
use bevy_reflect::{FromReflect, GetTypeRegistration, Reflect, TypePath};
use std::{any::TypeId, sync::Arc};

#[cfg(all(feature = "file_watcher", not(feature = "multi-threaded")))]
compile_error!(
"The \"file_watcher\" feature for hot reloading requires the \
\"multi-threaded\" feature to be functional.\n\
Consider either disabling the \"file_watcher\" feature or enabling \"multi-threaded\""
);

/// Provides "asset" loading and processing functionality. An [`Asset`] is a "runtime value" that is loaded from an [`AssetSource`],
/// which can be something like a filesystem, a network, etc.
///
Expand Down

0 comments on commit 96444b2

Please sign in to comment.