Skip to content

Commit e186c7c

Browse files
authored
Fix panic in custom_render_phase example (#17866)
# Objective Fix panic in `custom_render_phase`. This example was broken by #17764, but that breakage evolved into a panic after #17849. This new panic seems to illustrate the problem in a pretty straightforward way. ``` 2025-02-15T00:44:11.833622Z INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "macOS 15.3 Sequoia", kernel: "24.3.0", cpu: "Apple M4 Max", core_count: "16", memory: "64.0 GiB" } 2025-02-15T00:44:11.908328Z INFO bevy_render::renderer: AdapterInfo { name: "Apple M4 Max", vendor: 0, device: 0, device_type: IntegratedGpu, driver: "", driver_info: "", backend: Metal } 2025-02-15T00:44:12.314930Z INFO bevy_winit::system: Creating new window App (0v1) thread 'Compute Task Pool (1)' panicked at /Users/me/src/bevy/crates/bevy_ecs/src/system/function_system.rs:216:28: bevy_render::batching::gpu_preprocessing::batch_and_prepare_sorted_render_phase<custom_render_phase::Stencil3d, custom_render_phase::StencilPipeline> could not access system parameter ResMut<PhaseBatchedInstanceBuffers<Stencil3d, MeshUniform>> ``` ## Solution Add a `SortedRenderPhasePlugin` for the custom phase. ## Testing `cargo run --example custom_render_phase`
1 parent 137878a commit e186c7c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

examples/shader/custom_render_phase.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use bevy::{
4343
render_phase::{
4444
sort_phase_system, AddRenderCommand, CachedRenderPipelinePhaseItem, DrawFunctionId,
4545
DrawFunctions, InputUniformIndex, PhaseItem, PhaseItemExtraIndex, SetItemPipeline,
46-
SortedPhaseItem, ViewSortedRenderPhases,
46+
SortedPhaseItem, SortedRenderPhasePlugin, ViewSortedRenderPhases,
4747
},
4848
render_resource::{
4949
CachedRenderPipelineId, ColorTargetState, ColorWrites, Face, FragmentState, FrontFace,
@@ -54,7 +54,7 @@ use bevy::{
5454
renderer::RenderContext,
5555
sync_world::MainEntity,
5656
view::{ExtractedView, RenderVisibleEntities, RetainedViewEntity, ViewTarget},
57-
Extract, Render, RenderApp, RenderSet,
57+
Extract, Render, RenderApp, RenderDebugFlags, RenderSet,
5858
},
5959
};
6060
use nonmax::NonMaxU32;
@@ -113,7 +113,10 @@ struct DrawStencil;
113113
struct MeshStencilPhasePlugin;
114114
impl Plugin for MeshStencilPhasePlugin {
115115
fn build(&self, app: &mut App) {
116-
app.add_plugins((ExtractComponentPlugin::<DrawStencil>::default(),));
116+
app.add_plugins((
117+
ExtractComponentPlugin::<DrawStencil>::default(),
118+
SortedRenderPhasePlugin::<Stencil3d, MeshPipeline>::new(RenderDebugFlags::default()),
119+
));
117120
// We need to get the render app from the main app
118121
let Some(render_app) = app.get_sub_app_mut(RenderApp) else {
119122
return;

0 commit comments

Comments
 (0)