bevyengine / bevyengine/bevy

Stale textures while new assets loading

Open
#8,929 0 comments 0 reactions 0 assignees View on GitHub
A-Assets A-Rendering C-Bug
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## Bevy version

0.10.1

## \[Optional\] Relevant system information

```
2023-06-22T12:52:20.643800Z INFO winit::platform_impl::platform::x11::window: Guessed window scale factor: 1
2023-06-22T12:52:20.731391Z INFO bevy_render::renderer: AdapterInfo { name: "NVIDIA GeForce GTX 1050", vendor: 4318, device: 7297, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "530.41.03", backend: Vulkan }
2023-06-22T12:52:20.905245Z INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Linux rolling Arch Linux", kernel: "6.3.4-arch1-1", cpu: "AMD Ryzen 7 1700X Eight-Core Processor", core_count: "8", memory: "31.3 GiB" }
```

## What you did

I have a material with
```
#[texture(1)]
#[sampler(2)]
pub texture: Option>,
```

and a bind implementation of
```
impl AsBindGroupShaderType for ShotMaterial {
fn as_bind_group_shader_type(&self, _images: &RenderAssets) -> ShotMaterialUniform {
let mut flags = ShotMaterialFlags::NONE;
if self.texture.is_some() {
flags |= ShotMaterialFlags::TEXTURE;
}
ShotMaterialUniform {
size: self.size,
window_height: self.window_height,
pad: self.pad,
cards_x: self.cards_x,
card_w: self.card_w,
flags: flags.bits(),
}
}
}
```

This code w.r.t. texture is copied from bevy's built in `ColorMaterial` code, but I haven't tested with that directly.

When some state changes, I replace one `Some(...)` texture with a different `Some(...)` texture. The textures have different dimensions, and I update the rendering dimensions (size) at the same time.

## What went wrong

For a short duration, the old texture is rendered with the new size. This appears to correspond to the duration the new asset is being loaded.

## Additional information

I was able to work around this by setting `texture` to `None` for one system iteration - after that, even though the texture isn't loaded for several more frames, setting `texture` to the new texture handle causes the shader to treat the texture as missing (i.e. it stops drawing the old texture).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.