[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
@ -236,7 +236,6 @@ impl AssetServer {
|
|||||||
asset_path: AssetPath<'_>,
|
asset_path: AssetPath<'_>,
|
||||||
force: bool,
|
force: bool,
|
||||||
) -> Result<AssetPathId, AssetServerError> {
|
) -> Result<AssetPathId, AssetServerError> {
|
||||||
let asset_loader = self.get_path_asset_loader(asset_path.path())?;
|
|
||||||
let asset_path_id: AssetPathId = asset_path.get_id();
|
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
|
// 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;
|
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
|
// load the asset bytes
|
||||||
let bytes = match self.server.asset_io.load_path(asset_path.path()).await {
|
let bytes = match self.server.asset_io.load_path(asset_path.path()).await {
|
||||||
Ok(bytes) => bytes,
|
Ok(bytes) => bytes,
|
||||||
@ -708,7 +716,7 @@ mod test {
|
|||||||
_ => false,
|
_ => false,
|
||||||
});
|
});
|
||||||
|
|
||||||
assert_eq!(asset_server.get_load_state(handle), LoadState::NotLoaded);
|
assert_eq!(asset_server.get_load_state(handle), LoadState::Failed);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user