Overwriting an ExtendedMaterial with another ExtendedMaterial crashes bevy
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## Bevy version
0.16.1
maybe related to: https://github.com/bevyengine/bevy/issues/19838
## Relevant system information
```
2025-07-08T15:06:55.756508Z INFO bevy_render::renderer: AdapterInfo { name: "NVIDIA RTX A2000 Laptop GPU", vendor: 4318, device: 9656, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "553.62", backend: Vulkan }
2025-07-08T15:06:55.924385Z INFO bevy_render::batching::gpu_preprocessing: GPU preprocessing is fully supported on this device.
```
## What you did
I am trying to create debug views for my procedural terrain generation.
I have:
- one "normal" terrain shader: MeshMaterial3d>
- one "debug" terrain shader: MeshMaterial3d>
## What went wrong
I can use both shaders separately without problems. But when I try to change a terrain cluster (entity) from one material to the other, bevy crashes with the following errors:
```
thread 'Compute Task Pool (2)' panicked at C:\Users\___\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\bevy_pbr-0.16.1\src\prepass\mod.rs:952:79:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'Compute Task Pool (3)' panicked at C:\Users\___\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\bevy_pbr-0.16.1\src\material.rs:1023:79:
called `Option::unwrap()` on a `None` value
Encountered a panic in system `bevy_pbr::prepass::specialize_prepass_material_meshes>`!
Encountered a panic in system `bevy_pbr::material::specialize_material_meshes>`!
thread 'Compute Task Pool (0)' panicked at C:\Users\___\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\bevy_pbr-0.16.1\src\render\light.rs:1897:84:
called `Option::unwrap()` on a `None` value
Encountered a panic in system `bevy_pbr::render::light::specialize_shadows>`!
2025-07-08T15:07:01.764144Z WARN bevy_render::diagnostic::internal: Failed to download render statistics buffer: Error occurred when trying to async map a buffer
2025-07-08T15:07:01.764259Z WARN bevy_render::diagnostic::internal: Failed to download render statistics buffer: Error occurred when trying to async map a buffer
2025-07-08T15:07:01.764318Z WARN bevy_render::diagnostic::internal: Failed to download render statistics buffer: Error occurred when trying to async map a buffer
2025-07-08T15:07:01.764388Z WARN bevy_render::diagnostic::internal: Failed to download render statistics buffer: Error occurred when trying to async map a buffer
```
## Additional information
Both are simple shaders with a small uniform:
```
#[derive(Asset, AsBindGroup, Reflect, Debug, Clone)]
pub struct TerrainShader {
#[uniform(100)]
pub erosion_start: f32,
#[uniform(100)]
pub erosion_max: f32,
}
#[derive(Asset, AsBindGroup, Reflect, Debug, Clone)]
pub struct TerrainColoredTilesShader {
#[uniform(101)]
size_of_tile: f32
}
```
I try to overwrite the material like:
```
for surface in surfaces.iter() {
let mut entity_commands = commands.entity(surface);
// materials is a resource with MeshMaterial3d handles
entity_commands.insert(materials.terrain_colored_tiles.clone())
}
```
Contributor guide
Assessment
This issue has not been assessed yet.