bevyengine / bevyengine/bevy

Panic with DirectionalLight+Shadows+Camera

Open
#16,094 0 comments 0 reactions 0 assignees View on GitHub
A-Rendering C-Bug I-Regression S-Ready-For-Implementation
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## Bevy version
`0.15.0-rc.1`
Further: I have verified via `git bisect` that this panic was introduced in [de888a373de666ff9d1bbdf8275e7fb625584394](https://github.com/bevyengine/bevy/commit/de888a373de666ff9d1bbdf8275e7fb625584394) (https://github.com/bevyengine/bevy/pull/15554)
_(notable that this commit does not actually change the offending file, though perhaps that is the problem)_

## What I did

Add `DirectionalLight { shadows_enabled: true, ..default() }` to an entity that has a Camera.
_(You may reproduce by simply adding that snippet when spawning the Camera in the regular `3d/lighting` example)_

All three of those conditions are necessary to reproduce the bug
* Does not panic if `DirectionalLight` is replaced with `PointLight`
* Does not panic if shadows are disabled
* Does not panic if the Camera is removed

## What went wrong
```
thread 'main' panicked at crates\bevy_pbr\src\render\light.rs:1265:18:
called `Option::unwrap()` on a `None` value
```
https://github.com/bevyengine/bevy/blob/v0.15.0-rc.1/crates/bevy_pbr/src/render/light.rs#L1265

This is a bare `unwrap` with no comment indicating why it would be unreachable.
Otoh, if it is supposed to be reachable (yet truly catastrophic), then it really ought to be an `expect` with similar justification in the text.

Absent either of those, one has to trace back through the web of Components and Render World syncing to see why this condition could possibly arise (much less be justified in crashing the program when violated). If it's not clear, I'm on [team 'no panic'](https://github.com/bevyengine/bevy/issues/15979) :)

## Additional information

Final note: This issue is not about whether a 'light on camera' setup does/should work (I was just messing around when I ran into this);
I'm only concerned about the fact that it panics.

Contributor guide

Open the contributing guide

Research direction

Start with crates/bevy_pbr/src/render/light.rs at line 1265 and reproduce the panic by adding a shadow-enabled DirectionalLight to the Camera in the 3d/lighting example. Trace the relevant render-world state around the unwrap and ensure this light-and-camera setup no longer panics, while preserving the reported reproduction conditions.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
computer-graphics, game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.