Skip to content

Fix stale occlusion culling components#23555

Merged
alice-i-cecile merged 1 commit intobevyengine:mainfrom
kristoff3r:ks/occlusion-culling-fix
Mar 29, 2026
Merged

Fix stale occlusion culling components#23555
alice-i-cecile merged 1 commit intobevyengine:mainfrom
kristoff3r:ks/occlusion-culling-fix

Conversation

@kristoff3r
Copy link
Copy Markdown
Contributor

Objective

Fixes #23108

When occlusion culling gets disabled for a view we didn't clean up the generated components, which caused some later occlusion culling systems to run in an invalid state.

This problem was discovered recently, and while I haven't bisected it my guess is that it's been present since the retained render world. We could really use a more general approach to catching and/or preventing these issues with stale resources.

Solution

Remove stale resources in the prepare system before we make new ones.

Testing

cargo run --example occlusion_culling and press space a couple of times.

When occlusion culling gets disabled for a view we didn't clean up the
generated components, which caused some later occlusion culling systems
to run in an invalid state.
@kristoff3r kristoff3r added C-Bug An unexpected or incorrect behavior D-Trivial Nice and easy! A great choice to get started with Bevy A-Rendering Drawing game state to the screen S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Mar 28, 2026
@github-project-automation github-project-automation bot moved this to Needs SME Triage in Rendering Mar 28, 2026
Copy link
Copy Markdown
Contributor

@ChristopherBiscardi ChristopherBiscardi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice. I have confirmed that the previous validation warning (for downsample multisample depth bind group) no longer shows when switching between on/off in the occlusion culling example on macos.

@JMS55 JMS55 added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Mar 28, 2026
@beicause
Copy link
Copy Markdown
Contributor

How about using #[extract_component_sync_target(Self, ViewDepthPyramid, ViewDownsampleDepthBindGroup)] which is added in #23334

@kristoff3r
Copy link
Copy Markdown
Contributor Author

How about using #[extract_component_sync_target(Self, ViewDepthPyramid, ViewDownsampleDepthBindGroup)] which is added in #23334

I gave it a shot, but it's not trivial. The OcclusionCulling component is in bevy_render and the others are in bevy_core_pipeline, so it's not possible to use the macro. I could try to use SyncComponentPlugin manually, but I would have to move the ExtractComponentPlugin out of bevy_renders view module into MipGenerationPlugin to make the trait implementations to line up, which I think would silently break third party users.

@kristoff3r kristoff3r added this to the 0.19 milestone Mar 29, 2026
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Mar 29, 2026
Merged via the queue into bevyengine:main with commit 33a4eb5 Mar 29, 2026
49 checks passed
@github-project-automation github-project-automation bot moved this from Needs SME Triage to Done in Rendering Mar 29, 2026
splo pushed a commit to splo/bevy that referenced this pull request Mar 31, 2026
# Objective

Fixes bevyengine#23108

When occlusion culling gets disabled for a view we didn't clean up the
generated components, which caused some later occlusion culling systems
to run in an invalid state.

This problem was discovered recently, and while I haven't bisected it my
guess is that it's been present since the retained render world. We
could really use a more general approach to catching and/or preventing
these issues with stale resources.

## Solution

Remove stale resources in the prepare system before we make new ones.

## Testing

`cargo run --example occlusion_culling` and press space a couple of
times.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior D-Trivial Nice and easy! A great choice to get started with Bevy S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Occlusion culling example rendering error

5 participants