`AssetServer::get_load_state()` returns `NotLoaded` right after a call to `load()`
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## Bevy version
0.9.1
## What you did
Load a bunch of assets at once, which will increase the chance that an asset is not "immediately" loaded, that is there's an observable delay between the call to `AssetServer::load()` and the time the internal async load is started.
## What went wrong
`AssetServer::get_load_state()` returns `NotLoaded` instead of the expected `Loading`.
## Additional information
It looks like a race condition. `AssetServer::load()` enqueues the loading task via the `IoTaskPool`, but doesn't immediately update the `asset_sources` before returning. Later, when the loading task runs, the internal `load_async()` actually updates `asset_sources`. In the meantime, there's a short period of time where calling `AssetServer::get_load_state()` will query `asset_sources` and not find the asset, and therefore return `NotLoaded`.
From a user perspective, I believe the `AssetServer` should return `Loading` immediately after a call to `load()` returned. The fact the internal async loading task didn't yet start is an implementation detail that the user doesn't care about. `NotLoaded` makes it look like the asset is not even scheduled for loading, like the call to `load()` had somehow failed.
See also:
- #6135
- #7479
Contributor guide
Assessment
This issue has not been assessed yet.