Skip to content

Commit

Permalink
Don't reference non-existent default deferred lighting pass
Browse files Browse the repository at this point in the history
Fixes a crash when using DefaultPlugins with `PbrPlugin { add_default_deferred_lighting_plugin: false, ..default() }`
  • Loading branch information
CrushedPixel committed Dec 22, 2024
1 parent 2027700 commit 3ad3b1d
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions crates/bevy_pbr/src/ssr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use bevy_ecs::{
};
use bevy_image::BevyDefault as _;
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_render::render_graph::RenderGraph;
use bevy_render::{
extract_component::{ExtractComponent, ExtractComponentPlugin},
render_graph::{NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner},
Expand Down Expand Up @@ -233,15 +234,33 @@ impl Plugin for ScreenSpaceReflectionsPlugin {

render_app
.init_resource::<ScreenSpaceReflectionsPipeline>()
.init_resource::<SpecializedRenderPipelines<ScreenSpaceReflectionsPipeline>>()
.add_render_graph_edges(
.init_resource::<SpecializedRenderPipelines<ScreenSpaceReflectionsPipeline>>();

// only reference the default deferred lighting pass
// if it has been added
let has_default_deferred_lighting_pass = render_app
.world_mut()
.get_resource_mut::<RenderGraph>()
.unwrap()
.sub_graph(Core3d)
.get_node_state(NodePbr::DeferredLightingPass)
.is_ok();

if has_default_deferred_lighting_pass {
render_app.add_render_graph_edges(
Core3d,
(
NodePbr::DeferredLightingPass,
NodePbr::ScreenSpaceReflections,
Node3d::MainOpaquePass,
),
);
} else {
render_app.add_render_graph_edges(
Core3d,
(NodePbr::ScreenSpaceReflections, Node3d::MainOpaquePass),
);
}
}
}

Expand Down

0 comments on commit 3ad3b1d

Please sign in to comment.