-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
AssetServer LoadState API consistency #15237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AssetServer LoadState API consistency #15237
Conversation
2175185
to
6b17d95
Compare
It looks like your PR is a breaking change, but you didn't provide a migration guide. Could you add some context on what users should update when this change get released in a new version of Bevy? |
What else needs to be done before this is ready for review? |
I usually just wait for checks to pass first :) |
crates/bevy_asset/src/server/info.rs
Outdated
@@ -506,7 +514,7 @@ impl AssetInfos { | |||
if let Some(info) = self.get_mut(id) { | |||
info.loading_dependencies.remove(&loaded_asset_id); | |||
if info.loading_dependencies.is_empty() { | |||
// send dependencies loaded event | |||
// send dependencies loaded event (wouldn't this overwrite previous Failed state?) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems broken as is. Example: A depends on B and C.
- B fails to load.
- Line 624: B removed from
A.loading_dependencies
and - Line 628:
A.dep_load_state
is set to Failed - C successfully loads
- Line 515: C removed from
A.loading_dependencies
(now empty) - Line 518:
A.dep_load_state
overwritten to Loaded
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a new unit test that confirmed the previous impl was overwriting previously failed dependencies. Added this check to fix it.
crates/bevy_asset/src/server/info.rs
Outdated
info.dep_load_state = DependencyLoadState::Loaded; | ||
if !matches!(info.dep_load_state, DependencyLoadState::Failed(_)) { | ||
// send dependencies loaded event | ||
info.dep_load_state = DependencyLoadState::Loaded; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prior to this change, the added test dependency_load_states
would fail due to a successful dependency load overwriting a previous failed dependency load.
@@ -450,7 +458,7 @@ impl AssetInfos { | |||
RecursiveDependencyLoadState::Loaded | |||
} | |||
(_loading, 0) => RecursiveDependencyLoadState::Loading, | |||
(_loading, _failed) => RecursiveDependencyLoadState::Failed, | |||
(_loading, _failed) => RecursiveDependencyLoadState::Failed(rec_dep_error.unwrap()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To preserve the previous behavior, I separated the errors based on where they were found. I'm not sure this makes sense though. In general, the interaction between DependencyLoadState
and RecursiveDependencyLoadState
is pretty confusing.
IMO we should simplify to just LoadState
and DependencyLoadState
(which are affected by their own dependencies recursively) unless there is a clear use case for distinguishing between deps and recursive deps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally agree. Follow-up though :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of cleanup items, but I'm on board with this. I'm generally in favor of the error-handling cleanup you've mentioned as well, but let's keep this PR scoped.
I think I would prefer a Vec
of errors, but I'll defer to you on whether to do that in this PR or follow-up.
I also think a |
KK, let's get this merged first, then clean up the error handling, then move to a vec or hashmap of errors :) |
- implements consistently named AssertServer methods for asset, dependency, and recursive dependency load states - adds error to DependencyLoadState::Failed and RecursiveDependencyLoadState::Failed - fixes bug where successful dependency load overwrites previous dependency failed load state
28b5e84
to
260a7ae
Compare
cleanup items resolved :) |
crates/bevy_asset/src/server/mod.rs
Outdated
matches!(self.load_state(id), LoadState::Loaded) | ||
} | ||
|
||
/// Convenience method that returns true if the asset and all of its direct dependencies have been loaded. | ||
pub fn is_loaded_with_dependencies(&self, id: impl Into<UntypedAssetId>) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I seeing it right that current calls to is_loaded_with_dependencies
now has different semantics and that users should replace it with is_loaded_with_recursive_dependencies
to keep their code working as before? If so, this seems like an incredibly silent footgun. Users upgrading their version without looking at the migration guides will have no idea that their code is now slightly wrong.
If my assessment is correct, we should ensure that this cannot happen, e.g. by leaving the semantics in place and introducing a is_loaded_with_direct_dependencies
. I also don't like how the variant that you will usually want, namely is_loaded_with_recursive_dependencies
, has a longer / more technical name than is_loaded_with_dependencies
, which is probably not what you want.
But maybe I am misunderstanding the code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No misunderstanding, you are absolutely right. I will revert the name of is_loaded_with_recursive_dependencies
to is_loaded_with_dependencies
to preserve the original semantics. I will rename the check for self + direct deps to is_loaded_with_direct_dependencies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks! I think the breaking changes are minor and trivial enough that it's alright we're missing a migration guide.
Part of me wants to rename the LoadState returning methods as well to be consistent, but I think that belongs in a follow up PR focused on this: #15237 (comment) |
Objective
AssetServer::is_loaded_with_dependencies
should return aLoadState
. #15098Solution
Testing