From e549f143593e90197cb9bc39ab6fed355c8a6681 Mon Sep 17 00:00:00 2001 From: Nathan Ward Date: Tue, 8 Jun 2021 19:39:59 +0000 Subject: [PATCH] [assets] properly set `LoadState` with invalid asset extension (#2318) # Objective - Currently, when calling any of the `AssetServer`'s `load` functions, if the extension does not exist for the given path, the returned handle's load state is always `LoadState::NotLoaded`. - This is due to the `load_async` function early returning without properly creating a `SourceInfo` for the requested asset. - Fixes #2261 ## Solution - Add the `SourceInfo` prior to checking for valid extension loaders. And set the `LoadState` to `Failed` if the according loader does not exist. --- crates/bevy_asset/src/asset_server.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/bevy_asset/src/asset_server.rs b/crates/bevy_asset/src/asset_server.rs index d7b355b879..22b6463dca 100644 --- a/crates/bevy_asset/src/asset_server.rs +++ b/crates/bevy_asset/src/asset_server.rs @@ -236,7 +236,6 @@ impl AssetServer { asset_path: AssetPath<'_>, force: bool, ) -> Result { - let asset_loader = self.get_path_asset_loader(asset_path.path())?; let asset_path_id: AssetPathId = asset_path.get_id(); // load metadata and update source info. this is done in a scope to ensure we release the @@ -280,6 +279,15 @@ impl AssetServer { source_info.load_state = LoadState::Failed; }; + // get the according asset loader + let asset_loader = match self.get_path_asset_loader(asset_path.path()) { + Ok(loader) => loader, + Err(err) => { + set_asset_failed(); + return Err(err); + } + }; + // load the asset bytes let bytes = match self.server.asset_io.load_path(asset_path.path()).await { Ok(bytes) => bytes, @@ -708,7 +716,7 @@ mod test { _ => false, }); - assert_eq!(asset_server.get_load_state(handle), LoadState::NotLoaded); + assert_eq!(asset_server.get_load_state(handle), LoadState::Failed); } #[test]