Skip to content

Commit

Permalink
revert 'free_unused_asset_system' ordering to allow 1 frame delay for…
Browse files Browse the repository at this point in the history
… asset removal
  • Loading branch information
NathanSWard committed May 20, 2021
1 parent 01291b4 commit ab30709
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions crates/bevy_asset/src/asset_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,14 +525,13 @@ impl AssetServer {
}
}

fn free_unused_assets_system_ref(asset_server: &AssetServer) {
// note: order of these function is important.
asset_server.mark_unused_assets();
fn free_unused_assets_system_impl(asset_server: &AssetServer) {
asset_server.free_unused_assets();
asset_server.mark_unused_assets();
}

pub fn free_unused_assets_system(asset_server: Res<AssetServer>) {
free_unused_assets_system_ref(&asset_server);
free_unused_assets_system_impl(&asset_server);
}

#[cfg(test)]
Expand Down Expand Up @@ -761,18 +760,24 @@ mod test {

// mimics one full frame
let tick = |server: &AssetServer, assets: &mut Assets<PngAsset>| {
free_unused_assets_system_ref(server);
free_unused_assets_system_impl(server);
server.update_asset_storage(assets);
};

tick(&asset_server, &mut assets);
// asset should exist and be loaded at this point
assert_eq!(LoadState::Loaded, asset_server.get_load_state(id));
assert!(assets.get(&handle).is_some());

// after dropping the handle, next call to `tick` should
// remove the asset and reset the `LoadState`.
// after dropping the handle, next call to `tick` will prepare the assets for removal.
drop(handle);
tick(&asset_server, &mut assets);
assert_eq!(LoadState::Loaded, asset_server.get_load_state(id));
assert!(assets.get(id).is_some());

// second call to tick will actually remove the asset.
tick(&asset_server, &mut assets);
assert_eq!(LoadState::NotLoaded, asset_server.get_load_state(id));
assert!(assets.get(id).is_none());
}
}

0 comments on commit ab30709

Please sign in to comment.