Skip to content

Panic upon using a CameraProjection with DirectionalLight shadows #11799

Closed
@doonv

Description

@doonv

Bevy version

main (f84672b)

Relevant system information

If you cannot get Bevy to build or run on your machine, please include:

  • Rust: Stable + Nightly (Crashes on both)
  • Kubuntu 23.10
AdapterInfo { name: "NVIDIA GeForce RTX 3060", vendor: 4318, device: 9540, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "535.154.05", backend: Vulkan }

What you did

I wanted to use a custom CameraProjection.

use bevy::prelude::*;
use bevy::{
    core_pipeline::{
        core_3d::graph::SubGraph3d,
        tonemapping::{DebandDither, Tonemapping},
    },
    render::{
        camera::{CameraMainTextureUsages, CameraRenderGraph},
        primitives::Frustum,
        view::{ColorGrading, VisibleEntities},
    },
};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup)
        .run();
}

fn setup(mut commands: Commands) {
    commands.spawn(DirectionalLightBundle {
        directional_light: DirectionalLight {
            shadows_enabled: true, // This is required for it to panic, I don't know why
            ..default()
        },
        ..default()
    });
    
    // This is identical to `Camera3dBundle` except for the projection
    commands.spawn((
        Camera::default(),
        CameraRenderGraph::new(SubGraph3d),
        PerspectiveProjection {
            aspect_ratio: 1.0,
            fov: 90.0,
            near: 1.0,
            far: 1000.0,
        },
        VisibleEntities::default(),
        Frustum::default(),
        Transform::default(),
        GlobalTransform::default(),
        Camera3d::default(),
        Tonemapping::default(),
        DebandDither::Enabled,
        ColorGrading::default(),
        CameraMainTextureUsages::default(),
    ));
}

What went wrong

It turns out using a CameraProjection component directly on the camera instead of using it through Projection causes a panic. It even panics with built-in projections like PerspectiveProjection.

2024-02-09T21:40:51.187168Z  INFO bevy_winit::system: Creating new window "App" (0v1)
2024-02-09T21:40:51.187435Z  INFO log: Guessed window scale factor: 1    
2024-02-09T21:40:51.362996Z  INFO bevy_render::renderer: AdapterInfo { name: "NVIDIA GeForce RTX 3060", vendor: 4318, device: 9540, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "535.154.05", backend: Vulkan }
2024-02-09T21:40:51.875860Z  INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Linux 23.10 Ubuntu", kernel: "6.5.0-17-generic", cpu: "", core_count: "10", memory: "15.4 GiB" }
thread 'Compute Task Pool (1)' panicked at crates/bevy_pbr/src/render/light.rs:1139:18:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic in system `bevy_pbr::render::light::prepare_lights`!
thread 'main' panicked at crates/bevy_render/src/pipelined_rendering.rs:49:67:
called `Result::unwrap()` on an `Err` value: RecvError

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-RenderingDrawing game state to the screenC-BugAn unexpected or incorrect behaviorP-CrashA sudden unexpected crash

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions