Skip to content

Commit

Permalink
fix(assets): Sort asset dependency cids before updating parent cid (#286
Browse files Browse the repository at this point in the history
)

Simple fix for asset dependencies not being sorted correctly, fixes not
having a reliable cid for asset handle replication.

Fixes #285 (though we may consider a better solution in the future as
this requires two loops to gather / sort cids).
  • Loading branch information
MaxCWhitehead committed Dec 25, 2023
1 parent 69a1b4d commit b5a8f30
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions framework_crates/bones_asset/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,14 @@ impl AssetServer {
};

// Update Cid with the Cids of it's dependencies
dependencies.sort();

// TODO: Dependencies should be sorted as a consistent order is required to
// compute the same cid. We can't sort Vec<UntypedHandle>, runtime IDs vary each run.
//
// dependencies.sort();

// For now, gather cids and sort them before update
let mut dep_cids: Vec<Cid> = vec![];
for dep in &dependencies {
let dep_cid = loop {
let listener = self.load_progress.listen();
Expand All @@ -645,6 +652,12 @@ impl AssetServer {
};
break *cid;
};
// cid.update(dep_cid.0.as_slice());
dep_cids.push(dep_cid);
}

dep_cids.sort();
for dep_cid in dep_cids {
cid.update(dep_cid.0.as_slice());
}

Expand Down Expand Up @@ -710,8 +723,16 @@ impl AssetServer {
let sbox = loader.load(ctx, contents).await?;

// Update Cid with the Cids of it's dependencies
let mut dependencies = dependencies.iter().cloned().collect::<Vec<_>>();
dependencies.sort();
let dependencies = dependencies.iter().cloned().collect::<Vec<_>>();

// TODO: Dependencies should be sorted as a consistent order is required to
// compute the same cid. We can't sort Vec<UntypedHandle>, runtime IDs vary each run.
//
// dependencies.sort();

// For now, gather cids and sort them before update
let mut dep_cids: Vec<Cid> = vec![];

for dep in &dependencies {
let dep_cid = loop {
let listener = self.load_progress.listen();
Expand All @@ -721,6 +742,11 @@ impl AssetServer {
};
break *cid;
};
dep_cids.push(dep_cid);
// cid.update(dep_cid.0.as_slice());
}
dep_cids.sort();
for dep_cid in dep_cids {
cid.update(dep_cid.0.as_slice());
}

Expand Down

0 comments on commit b5a8f30

Please sign in to comment.