mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 04:33:37 +00:00
[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.
This commit is contained in:
parent
ac04c71d97
commit
e549f14359
1 changed files with 10 additions and 2 deletions
|
@ -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
|
||||
|
@ -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]
|
||||
|
|
Loading…
Reference in a new issue