Skip to content

Commit

Permalink
Fix point light count limit (bevyengine#16062)
Browse files Browse the repository at this point in the history
# Objective

- I made a mistake in bevyengine#15902, specifically [this
diff](bevyengine@e2faedb)
-- the `point_light_count` variable is used for all point lights, not
just shadow mapped ones, so I cannot add `.min(max_texture_cubes)`
there. (Despite `spot_light_count` having `.min(..)`)

It may have broken code like this (where `index` is index of
`point_light` vec):


https://github.com/bevyengine/bevy/blob/9930df83ed42008f7eb2c02cc7350040f0250c2e/crates/bevy_pbr/src/render/light.rs#L848-L850

and also causes panic here:

https://github.com/bevyengine/bevy/blob/9930df83ed42008f7eb2c02cc7350040f0250c2e/crates/bevy_pbr/src/render/light.rs#L1173-L1174

## Solution

- Adds `.min(max_texture_cubes)` directly to the loop where texture
views for point lights are created.

## Testing

- `lighting` example (with the directional light removed; original
example doesn't crash as only 1 directional-or-spot light in total is
shadow-mapped on webgl) no longer crashes on webgl
  • Loading branch information
akimakinai authored Oct 22, 2024
1 parent 2223f6e commit 50d38f2
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions crates/bevy_pbr/src/render/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,7 @@ pub fn prepare_lights(
let point_light_count = point_lights
.iter()
.filter(|light| light.1.spot_light_angles.is_none())
.count()
.min(max_texture_cubes);
.count();

let point_light_volumetric_enabled_count = point_lights
.iter()
Expand Down Expand Up @@ -1060,7 +1059,7 @@ pub fn prepare_lights(
for &(light_entity, light, (point_light_frusta, _)) in point_lights
.iter()
// Lights are sorted, shadow enabled lights are first
.take(point_light_count)
.take(point_light_count.min(max_texture_cubes))
{
let Ok(mut light_view_entities) = light_view_entities.get_mut(light_entity) else {
continue;
Expand Down

0 comments on commit 50d38f2

Please sign in to comment.