Skip to content

Commit

Permalink
[assets] properly set LoadState with invalid asset extension (bevye…
Browse files Browse the repository at this point in the history
…ngine#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 bevyengine#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.
  • Loading branch information
NathanSWard authored and ostwilkens committed Jul 27, 2021
1 parent 72af27b commit 67ab0af
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions crates/bevy_asset/src/asset_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ impl AssetServer {
asset_path: AssetPath<'_>,
force: bool,
) -> Result<AssetPathId, AssetServerError> {
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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 67ab0af

Please sign in to comment.