only set up processed source if asset plugin is not unprocessed (#10123)

# Objective

- Since #9885, running on an iOS device crashes trying to create the
processed folder
- This only happens on real device, not on the simulator

## Solution

- Setup processed assets only if needed
This commit is contained in:
François 2023-10-15 20:20:29 +02:00 committed by GitHub
parent 3866b1cc19
commit 5781806e72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 11 deletions

View File

@ -241,20 +241,25 @@ impl AssetSourceBuilder {
/// Returns a builder containing the "platform default source" for the given `path` and `processed_path`. /// Returns a builder containing the "platform default source" for the given `path` and `processed_path`.
/// For most platforms, this will use [`FileAssetReader`](crate::io::file::FileAssetReader) / [`FileAssetWriter`](crate::io::file::FileAssetWriter), /// For most platforms, this will use [`FileAssetReader`](crate::io::file::FileAssetReader) / [`FileAssetWriter`](crate::io::file::FileAssetWriter),
/// but some platforms (such as Android) have their own default readers / writers / watchers. /// but some platforms (such as Android) have their own default readers / writers / watchers.
pub fn platform_default(path: &str, processed_path: &str) -> Self { pub fn platform_default(path: &str, processed_path: Option<&str>) -> Self {
Self::default() let default = Self::default()
.with_reader(AssetSource::get_default_reader(path.to_string())) .with_reader(AssetSource::get_default_reader(path.to_string()))
.with_writer(AssetSource::get_default_writer(path.to_string())) .with_writer(AssetSource::get_default_writer(path.to_string()))
.with_watcher(AssetSource::get_default_watcher( .with_watcher(AssetSource::get_default_watcher(
path.to_string(), path.to_string(),
Duration::from_millis(300), Duration::from_millis(300),
)) ));
.with_processed_reader(AssetSource::get_default_reader(processed_path.to_string())) if let Some(processed_path) = processed_path {
.with_processed_writer(AssetSource::get_default_writer(processed_path.to_string())) default
.with_processed_watcher(AssetSource::get_default_watcher( .with_processed_reader(AssetSource::get_default_reader(processed_path.to_string()))
processed_path.to_string(), .with_processed_writer(AssetSource::get_default_writer(processed_path.to_string()))
Duration::from_millis(300), .with_processed_watcher(AssetSource::get_default_watcher(
)) processed_path.to_string(),
Duration::from_millis(300),
))
} else {
default
}
} }
} }
@ -315,7 +320,7 @@ impl AssetSourceBuilders {
} }
/// Initializes the default [`AssetSourceBuilder`] if it has not already been set. /// Initializes the default [`AssetSourceBuilder`] if it has not already been set.
pub fn init_default_source(&mut self, path: &str, processed_path: &str) { pub fn init_default_source(&mut self, path: &str, processed_path: Option<&str>) {
self.default self.default
.get_or_insert_with(|| AssetSourceBuilder::platform_default(path, processed_path)); .get_or_insert_with(|| AssetSourceBuilder::platform_default(path, processed_path));
} }

View File

@ -122,7 +122,11 @@ impl Plugin for AssetPlugin {
let mut sources = app let mut sources = app
.world .world
.get_resource_or_insert_with::<AssetSourceBuilders>(Default::default); .get_resource_or_insert_with::<AssetSourceBuilders>(Default::default);
sources.init_default_source(&self.file_path, &self.processed_file_path); sources.init_default_source(
&self.file_path,
(!matches!(self.mode, AssetMode::Unprocessed))
.then_some(self.processed_file_path.as_str()),
);
embedded.register_source(&mut sources); embedded.register_source(&mut sources);
} }
{ {