-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Assets are dropped although strong handles are kept in a resource #2347
Comments
it's expected, you're dropping the strong handles here: https://github.com/NiklasEi/bevy_unloading_assets_example/blob/main/src/main.rs#L14-L15 if you apply this diff you won't see the issue in your example: diff --git a/src/main.rs b/src/main.rs
index dcc3720..494c71f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -11,8 +11,8 @@ fn check_asset_handles(asset_server: Res<AssetServer>, textures: Res<TextureAsse
fn start_loading(mut commands: Commands, asset_server: Res<AssetServer>) {
let mut handle_ids = vec![];
- handle_ids.push(asset_server.load_untyped("textures/player.png").id);
- handle_ids.push(asset_server.load_untyped("textures/tree.png").id);
+ handle_ids.push(asset_server.load_untyped("textures/player.png"));
+ handle_ids.push(asset_server.load_untyped("textures/tree.png"));
commands.insert_resource(LoadingHandles {
handles: handle_ids,
@@ -25,7 +25,9 @@ fn check_loading(
mut state: ResMut<State<AppState>>,
loading_handles: Res<LoadingHandles>,
) {
- if asset_server.get_group_load_state(loading_handles.handles.clone()) == LoadState::Loaded {
+ if asset_server.get_group_load_state(loading_handles.handles.iter().map(|h| h.id))
+ == LoadState::Loaded
+ {
commands.insert_resource(TextureAssets {
player: asset_server.get_handle("textures/player.png"),
tree: asset_server.get_handle("textures/tree.png"),
@@ -42,7 +44,7 @@ enum AppState {
}
struct LoadingHandles {
- handles: Vec<HandleId>,
+ handles: Vec<HandleUntyped>,
}
struct TextureAssets { |
That explains a lot, thank you! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bevy version
Latest commit
71bf07f5c085b9c02cbe5337040337c3ed8b0002
Operating system & version
Ubuntu 18.04
What you did
Load png files in a State. When they are loaded, store strong handles to the textures in a resource and switch to a different state. Now I print out the asset loading state in each frame.
What you expected to happen
The asset handles should be kept in loaded state since there are strong handles for them stored in a resource.
What actually happened
The assets are unloaded after a very short time. The following output is one line per frame. From the third frame on the assets are no longer loaded.
Additional information
The code for a minimal example producing the above logs can be found here: https://github.com/NiklasEi/bevy_unloading_assets_example
I can consistently reproduce this issue in debug and in release mode.
The text was updated successfully, but these errors were encountered: