Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

ECS: Assets on web keep re-downloading (help: banging head against the wall) #13490

Closed
simbleau opened this issue May 24, 2024 · 1 comment
Closed
Labels
A-Assets Load files from disk to use for things like images, models, and sounds O-Web Specific to web (WASM) builds

Comments

@simbleau
Copy link
Contributor

Bevy version

0.13

The issue

I have a chat room, and when a message comes in, there could be emojis that need to be downloaded for display. Those emojis need to be fully downloaded so that I can properly scale them!

Here's my system that spawns the chats:

pub fn spawn_chat_bubbles(
    mut commands: Commands,
    asset_server: Res<AssetServer>,
    fonts: Res<Assets<VelloFont>>,
    query_bubbles: Query<(Entity, &ChatBubble), Without<Children>>,
) {
    for (entity, chat) in query_bubbles.iter() {
        match chat {
            ChatBubble::Chat { message, .. } => {
                let handle = asset_server
                    .load::<VelloFont>("remote://fonts/Inconsolata_UltraExpanded-SemiBold.ttf");
                info!("handle: {handle:?}");
                let Some(font) = fonts.get(&handle) else {
                    warn!("asset does not exist");
                    continue;
                };
     ...

All I'm trying to do is assert that the asset needs to be fully loaded before we can spawn it in.

The result?

image

I cannot explain this.

It re-downloads every update, instead of waiting for the existing handle to finish loading.

Furthermore, it appears that the handle stays to be index 0 generation 0 until it finishes downloading, then it just gives me a new generation handle every update and refuses to give me the downloaded asset!

Can anyone explain this?

I saw @mockersf had a very similar discussion a while back, although it makes no sense 3 years later: #1863

@simbleau simbleau added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels May 24, 2024
@alice-i-cecile alice-i-cecile added A-Assets Load files from disk to use for things like images, models, and sounds O-Web Specific to web (WASM) builds S-Needs-Investigation This issue requires detective work to figure out what's going wrong and removed S-Needs-Triage This issue needs to be labelled labels May 24, 2024
@bushrat011899
Copy link
Contributor

I believe the issue here is you're dropping the Handle on each frame;

fn get_handle(asset_server: Res<AssetServer>, fonts: Res<Assets<VelloFont>>) {
    // Handle created and loading started
    let handle = asset_server.load::<VelloFont>("...");
    
    let Some(font) = fonts.get(&handle) else {
        // Highly likely the asset hasn't loaded immediately (latency, etc.)
        // Because of that, this function always returns
        warn!("asset does not exist");
        return;
        // Now that we've returned, the Handle is dropped, which causes the load to be cancelled
    };
    // ...
}

Instead, try storing the Handle in a resource (or an Entity as a Component). That way the Handle will survive long enough for the load to complete.

@alice-i-cecile alice-i-cecile added S-User-Error This issue was caused by a mistake in the user's approach and removed C-Bug An unexpected or incorrect behavior S-Needs-Investigation This issue requires detective work to figure out what's going wrong S-User-Error This issue was caused by a mistake in the user's approach labels May 24, 2024
@bevyengine bevyengine locked and limited conversation to collaborators May 24, 2024
@alice-i-cecile alice-i-cecile converted this issue into discussion #13491 May 24, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
A-Assets Load files from disk to use for things like images, models, and sounds O-Web Specific to web (WASM) builds
Projects
None yet
Development

No branches or pull requests

3 participants