Description
Bevy version
bevy 0.16.0-rc.4
What you did
I'm not quite sure what the minimal setup for this is, but I could create an always crashing setup:
- A
PointLight
with shadow_enabled - A
Mesh
withNoFrustumCulling
- A
Camera
moving away from the light
Then: Despawning the mesh after the camera moved some distance away.
Minimal code:
use bevy::{prelude::*, render::view::NoFrustumCulling};
const CAM_Y: f32 = 0.;
const ZOOM: f32 = 30.;
const SPEED: f32 = 30.;
fn main(){
let mut app = App::new();
app .add_plugins(DefaultPlugins)
.add_systems(Startup,startup)
.add_systems(Update,( move_camera, despawn ))
.run();
}
fn startup(
mut cmd: Commands,
mut ass: ResMut<Assets<Mesh>>,
mut ase: ResMut<Assets<StandardMaterial>>
){
cmd.spawn((
Transform::from_xyz(0.,CAM_Y,ZOOM),
Camera3d::default(),
));
cmd.spawn((
Mesh3d(ass.add(Cuboid::new(1.,1.,1.))),
MeshMaterial3d(ase.add(Color::srgb(1.,0.,0.))),
NoFrustumCulling
));
cmd.spawn(PointLight{
shadows_enabled: true,
..default()
});
}
fn move_camera(
mut query: Query<(&mut Transform,Has<Camera>),With<Camera>>,
time: Res<Time>,
){
for (mut t,_) in &mut query {
t.translation.y += time.delta_secs() * SPEED;
}
}
// despawn after 2 seconds
fn despawn(
mut cmd: Commands,
query: Query<Entity,With<Mesh3d>>,
time: Res<Time>,
mut delay: Local<f32>
){
*delay += time.delta_secs();
if *delay < 2. {return}
for e in &query {
cmd.entity(e).despawn();
}
}
What went wrong
It always crashes here (on linux 6.13.8-arch1-1
) :
thread 'Compute Task Pool (15)' panicked at ~/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/bevy_pbr-0.16.0-rc.4/src/render/light.rs:1820:84:
called `Option::unwrap()` on a `None` value
Encountered a panic in system `bevy_pbr::render::light::specialize_shadows<bevy_pbr::pbr_material::StandardMaterial>`!
Additional information
-
This DOES panic, even if the Mesh is moved far away from the light before the despawn
- e.g.: after 1 sec: move mesh to Y:1000. | after 2 secs: despawn | => panic
-
This DOESN'T panic when the camera is moving slower or is zoomed out more
- e.g. set
SPEED=15.;
orZOOM=200.;
- e.g. set
-
This DOESN'T panic when the light was never 'in view' of the Camera
- e.g. set
CAM_Y=50.;
- e.g. set
-
This DOESN'T panic when the Mesh doesn't have
NoFrustumCulling
-
This DIDN'T panic in bevy_pbr
0.16.0-rc.3
I believe there are more setups where this happens even without using NoFrustumCulling
, but that's the only minimal one I could come up with.
Note: The panic is the same as in #18809 and may be related.