Skip to content
This repository was archived by the owner on Sep 8, 2024. It is now read-only.

Conversation

yaymukund
Copy link

When textures are rendered, there is a placeholder image that flashes for a single frame before the actual image. Here is an example of how it looks:

Screenshot 2024-01-13 at 5 59 11 PM

Example reproduction:

impl GameLoop for Game {
    fn new(_c: &mut EngineState) -> Self {
        load_multiple_textures(
            // Includes the "monkey" texture.
            crate::constants::TEXTURES
                .iter()
                .map(|(a, b)| (a.to_string(), b.to_string()))
                .collect_vec(),
        );

        clear_background(BLACK);
        Self
    }

    fn update(&mut self, c: &mut EngineContext) {
        if assets_loaded() < assets_queued_total() {
            println!("{}/{} loaded", assets_loaded(), assets_queued_total());
            return;
        }

        draw_sprite(
            texture_id("monkey"),
            vec2(5.0, 0.0),
            WHITE,
            0,
            vec2(2.60, 3.15),
        );
    }
}

Here's my attempt to track it down:

  1. run_early_update_stages() processes the asset queues...
  2. ...and then spawns an async task that does inc_assets_loaded() saying it is "loaded." It is not actually loaded yet.
  3. The renderer update can't find the texture and instead defaults to the "error" texture id, which is very similar to that image I linked above.
  4. Sometime between the renderer update and the next frame, the texture gets loaded. I am still not sure where this hapens.

Fix in this branch. We just put off the rendering by 1 frame.

@yaymukund
Copy link
Author

This doesn't seem to fix things for Sprite::new

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant