Skip to content

Commit

Permalink
Fix deactivated camera still being used in render world
Browse files Browse the repository at this point in the history
Switch to retained render world causes the extracted cameras in render
world to not be removed until camera in main world is despawned.
When extracting data from main world inactive cameras are skipped.
Therefore camera that was active and became inactive has a retained
`ExtractedCamera` component from previous frames (when it was active) and
is processed the same way as if it were active (there is no `active` field
on `ExtractedCamera`). This breakes switching between cameras in
`render_primitives` example.

Fix it by removing `ExtractedCamera` and related components from inactive
cameras.
Note that despawning inactive camera seems to be bad option because
they are spawned using `SyncToRenderWorld` component.

Fixes #15822
  • Loading branch information
rafalh committed Oct 16, 2024
1 parent b109787 commit cfd614c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crates/bevy_render/src/camera/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,8 +1054,12 @@ pub fn extract_cameras(
) in query.iter()
{
if !camera.is_active {
commands.entity(render_entity).remove::<RenderVisibleEntities>();
commands.entity(render_entity).remove::<ExtractedCamera>();
commands.entity(render_entity).remove::<ExtractedView>();
continue;
}

let color_grading = color_grading.unwrap_or(&ColorGrading::default()).clone();

if let (
Expand Down

0 comments on commit cfd614c

Please sign in to comment.