Skip to content

Commit 0a2e645

Browse files
authored
Add comments explaining why the reloading code is so complex. (#22264)
# Objective - Fixes #21222. ## Solution - Give an explanation, and add a TODO. Note I didn't write this code, so I'm "guessing" on the rationale - but it's an educated guess!
1 parent 6458934 commit 0a2e645

File tree

1 file changed

+10
-0
lines changed
  • crates/bevy_asset/src/server

1 file changed

+10
-0
lines changed

crates/bevy_asset/src/server/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,8 @@ impl AssetServer {
887887
.spawn(async move {
888888
let mut reloaded = false;
889889

890+
// First, try to reload the asset for any handles to that path. This will try both
891+
// root assets and subassets.
890892
let requests = server
891893
.read_infos()
892894
.get_path_handles(&path)
@@ -902,6 +904,14 @@ impl AssetServer {
902904
}
903905
}
904906

907+
// If the above section failed, and there are still living subassets (aka we should
908+
// reload), then just try doing an untyped load. This helps catch cases where the
909+
// root asset has been dropped, but all its subassets are still being used (in which
910+
// case the above section would have tried to find the loader with the root asset's
911+
// type and loaded it). Hopefully the untyped load will find the right loader and
912+
// reload all the subassets (though this is not guaranteed).
913+
// TODO: Make sure we use the same loader as the original load (e.g., by storing a
914+
// map from asset index to loader).
905915
if !reloaded && server.read_infos().should_reload(&path) {
906916
server.write_infos().stats.started_load_tasks += 1;
907917
match server.load_internal(None, path.clone(), true, None).await {

0 commit comments

Comments
 (0)