-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace unwraps with expects in bevy_app, bevy_audio, bevy_core, and bevy_core_pipeline #3913
Changes from all commits
fd941cc
8def886
a04e8a1
82d361d
b31ffb8
045ef66
898585a
d40e943
2c0495c
61e31d8
7c58405
e9da0e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -122,7 +122,10 @@ impl FixedTimestep { | |||||
) -> ShouldRun { | ||||||
let should_run = state.update(&time); | ||||||
if let Some(ref label) = state.label { | ||||||
let res_state = fixed_timesteps.fixed_timesteps.get_mut(label).unwrap(); | ||||||
let res_state = fixed_timesteps | ||||||
.fixed_timesteps | ||||||
.get_mut(label) | ||||||
.unwrap_or_else(|| panic!("Could not find a FixedTimestep labeled {label}")); | ||||||
res_state.step = state.step; | ||||||
res_state.accumulator = state.accumulator; | ||||||
} | ||||||
|
@@ -206,7 +209,9 @@ impl System for FixedTimestep { | |||||
Box::new(Self::prepare_system.config(|c| c.0 = Some(self.state.clone()))); | ||||||
self.internal_system.initialize(world); | ||||||
if let Some(ref label) = self.state.label { | ||||||
let mut fixed_timesteps = world.get_resource_mut::<FixedTimesteps>().unwrap(); | ||||||
let mut fixed_timesteps = world | ||||||
.get_resource_mut::<FixedTimesteps>() | ||||||
.expect("Could not find resource FixedTimesteps. It can be added with CorePlugin, DefaultPlugins, or MinimalPlugins"); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
fixed_timesteps.fixed_timesteps.insert( | ||||||
label.clone(), | ||||||
FixedTimestepState { | ||||||
|
@@ -254,25 +259,45 @@ mod test { | |||||
// if time does not progress, the step does not run | ||||||
schedule.run(&mut world); | ||||||
schedule.run(&mut world); | ||||||
assert_eq!(0, *world.get_resource::<Count>().unwrap()); | ||||||
assert_eq!( | ||||||
0, | ||||||
*world | ||||||
.get_resource::<Count>() | ||||||
.expect("Could not get the `Count` resource from the `World`") | ||||||
); | ||||||
assert_eq!(0., get_accumulator_deciseconds(&world)); | ||||||
|
||||||
// let's progress less than one step | ||||||
advance_time(&mut world, instance, 0.4); | ||||||
schedule.run(&mut world); | ||||||
assert_eq!(0, *world.get_resource::<Count>().unwrap()); | ||||||
assert_eq!( | ||||||
0, | ||||||
*world | ||||||
.get_resource::<Count>() | ||||||
.expect("Could not find `Count` in the `World`.") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
); | ||||||
assert_eq!(4., get_accumulator_deciseconds(&world)); | ||||||
|
||||||
// finish the first step with 0.1s above the step length | ||||||
advance_time(&mut world, instance, 0.6); | ||||||
schedule.run(&mut world); | ||||||
assert_eq!(1, *world.get_resource::<Count>().unwrap()); | ||||||
assert_eq!( | ||||||
1, | ||||||
*world | ||||||
.get_resource::<Count>() | ||||||
.expect("Could not find `Count` in the `World`.") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
); | ||||||
assert_eq!(1., get_accumulator_deciseconds(&world)); | ||||||
|
||||||
// runs multiple times if the delta is multiple step lengths | ||||||
advance_time(&mut world, instance, 1.7); | ||||||
schedule.run(&mut world); | ||||||
assert_eq!(3, *world.get_resource::<Count>().unwrap()); | ||||||
assert_eq!( | ||||||
3, | ||||||
*world | ||||||
.get_resource::<Count>() | ||||||
.expect("Could not find `Count` in the `World`.") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
); | ||||||
assert_eq!(2., get_accumulator_deciseconds(&world)); | ||||||
} | ||||||
|
||||||
|
@@ -283,16 +308,18 @@ mod test { | |||||
fn advance_time(world: &mut World, instance: Instant, seconds: f32) { | ||||||
world | ||||||
.get_resource_mut::<Time>() | ||||||
.unwrap() | ||||||
.expect("Could not find `Time` in the `World`.") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
.update_with_instant(instance.add(Duration::from_secs_f32(seconds))); | ||||||
} | ||||||
|
||||||
fn get_accumulator_deciseconds(world: &World) -> f64 { | ||||||
world | ||||||
.get_resource::<FixedTimesteps>() | ||||||
.unwrap() | ||||||
.expect("Could not find `FixedTimesteps` in the 'World'.") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
.get(LABEL) | ||||||
.unwrap() | ||||||
.unwrap_or_else(|| { | ||||||
panic!("Could not find a resource of the appropriate label: {LABEL}",) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}) | ||||||
.accumulator | ||||||
.mul(10.) | ||||||
.round() | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -51,7 +51,9 @@ impl Node for ClearPassNode { | |||||
) -> Result<(), NodeRunError> { | ||||||
let mut cleared_targets = HashSet::new(); | ||||||
let clear_color = world.get_resource::<ClearColor>().unwrap(); | ||||||
let render_target_clear_colors = world.get_resource::<RenderTargetClearColors>().unwrap(); | ||||||
let render_target_clear_colors = world | ||||||
.get_resource::<RenderTargetClearColors>() | ||||||
.expect("Could not find `ClearColor` resource in the `World`."); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
// This gets all ViewTargets and ViewDepthTextures and clears its attachments | ||||||
// TODO: This has the potential to clear the same target multiple times, if there | ||||||
|
@@ -89,8 +91,12 @@ impl Node for ClearPassNode { | |||||
// TODO: This is a hack to ensure we don't call present() on frames without any work, | ||||||
// which will cause panics. The real fix here is to clear "render targets" directly | ||||||
// instead of "views". This should be removed once full RenderTargets are implemented. | ||||||
let windows = world.get_resource::<ExtractedWindows>().unwrap(); | ||||||
let images = world.get_resource::<RenderAssets<Image>>().unwrap(); | ||||||
let windows = world | ||||||
.get_resource::<ExtractedWindows>() | ||||||
.expect("Could not find `ExtractedWindows` resource in `World`."); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
let images = world | ||||||
.get_resource::<RenderAssets<Image>>() | ||||||
.expect("Could not find `RenderAssets` resource in `World`."); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
for target in render_target_clear_colors.colors.keys().cloned().chain( | ||||||
windows | ||||||
.values() | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -176,7 +176,7 @@ impl Plugin for CorePipelinePlugin { | |||||
draw_3d_graph::node::MAIN_PASS, | ||||||
MainPass3dNode::IN_VIEW, | ||||||
) | ||||||
.unwrap(); | ||||||
.expect("Could not add slot edge to `RenderGraph`."); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something to consider before throwing expects onto more "internal" non-user facing code: static strings are compiled into the binary. I don't think we want to bloat bevy apps with a bunch of "internal error messages", especially in cases like these where the context of the code is as good (if not better) for debugging than the message in the expect (for a Bevy Engine dev debugging a user-reported error). |
||||||
graph.add_sub_graph(draw_3d_graph::NAME, draw_3d_graph); | ||||||
|
||||||
let mut clear_graph = RenderGraph::default(); | ||||||
|
@@ -187,11 +187,11 @@ impl Plugin for CorePipelinePlugin { | |||||
graph.add_node(node::MAIN_PASS_DRIVER, MainPassDriverNode); | ||||||
graph | ||||||
.add_node_edge(node::MAIN_PASS_DEPENDENCIES, node::MAIN_PASS_DRIVER) | ||||||
.unwrap(); | ||||||
.expect("Could not add node edge to `RenderGraph`."); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
graph.add_node(node::CLEAR_PASS_DRIVER, ClearPassDriverNode); | ||||||
graph | ||||||
.add_node_edge(node::CLEAR_PASS_DRIVER, node::MAIN_PASS_DRIVER) | ||||||
.unwrap(); | ||||||
.expect("Could not add node edge to `RenderGraph`."); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
} | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -55,7 +55,7 @@ impl Node for MainPass2dNode { | |||||||||
|
||||||||||
let draw_functions = world | ||||||||||
.get_resource::<DrawFunctions<Transparent2d>>() | ||||||||||
.unwrap(); | ||||||||||
.expect("Could not find `DrawFunctions` resource in the `World`."); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
let render_pass = render_context | ||||||||||
.command_encoder | ||||||||||
|
@@ -64,7 +64,9 @@ impl Node for MainPass2dNode { | |||||||||
let mut draw_functions = draw_functions.write(); | ||||||||||
let mut tracked_pass = TrackedRenderPass::new(render_pass); | ||||||||||
for item in &transparent_phase.items { | ||||||||||
let draw_function = draw_functions.get_mut(item.draw_function).unwrap(); | ||||||||||
let draw_function = draw_functions | ||||||||||
.get_mut(item.draw_function) | ||||||||||
.expect("Could not get draw function."); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
draw_function.draw(world, &mut tracked_pass, view_entity, item); | ||||||||||
} | ||||||||||
Ok(()) | ||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -83,7 +83,9 @@ impl Node for MainPass3dNode { | |||||||||
let mut draw_functions = draw_functions.write(); | ||||||||||
let mut tracked_pass = TrackedRenderPass::new(render_pass); | ||||||||||
for item in &opaque_phase.items { | ||||||||||
let draw_function = draw_functions.get_mut(item.draw_function).unwrap(); | ||||||||||
let draw_function = draw_functions | ||||||||||
.get_mut(item.draw_function) | ||||||||||
.expect("Could not get draw function."); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
draw_function.draw(world, &mut tracked_pass, view_entity, item); | ||||||||||
} | ||||||||||
} | ||||||||||
|
@@ -109,15 +111,19 @@ impl Node for MainPass3dNode { | |||||||||
}), | ||||||||||
}; | ||||||||||
|
||||||||||
let draw_functions = world.get_resource::<DrawFunctions<AlphaMask3d>>().unwrap(); | ||||||||||
let draw_functions = world | ||||||||||
.get_resource::<DrawFunctions<AlphaMask3d>>() | ||||||||||
.expect("Could not get `DrawFunctions` resource from the `World`."); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
let render_pass = render_context | ||||||||||
.command_encoder | ||||||||||
.begin_render_pass(&pass_descriptor); | ||||||||||
let mut draw_functions = draw_functions.write(); | ||||||||||
let mut tracked_pass = TrackedRenderPass::new(render_pass); | ||||||||||
for item in &alpha_mask_phase.items { | ||||||||||
let draw_function = draw_functions.get_mut(item.draw_function).unwrap(); | ||||||||||
let draw_function = draw_functions | ||||||||||
.get_mut(item.draw_function) | ||||||||||
.expect("Could not get draw function."); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
draw_function.draw(world, &mut tracked_pass, view_entity, item); | ||||||||||
} | ||||||||||
} | ||||||||||
|
@@ -147,15 +153,17 @@ impl Node for MainPass3dNode { | |||||||||
|
||||||||||
let draw_functions = world | ||||||||||
.get_resource::<DrawFunctions<Transparent3d>>() | ||||||||||
.unwrap(); | ||||||||||
.expect("Could not get `DrawFunctions` resource from the `World`."); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
let render_pass = render_context | ||||||||||
.command_encoder | ||||||||||
.begin_render_pass(&pass_descriptor); | ||||||||||
let mut draw_functions = draw_functions.write(); | ||||||||||
let mut tracked_pass = TrackedRenderPass::new(render_pass); | ||||||||||
for item in &transparent_phase.items { | ||||||||||
let draw_function = draw_functions.get_mut(item.draw_function).unwrap(); | ||||||||||
let draw_function = draw_functions | ||||||||||
.get_mut(item.draw_function) | ||||||||||
.expect("Could not get draw function."); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
draw_function.draw(world, &mut tracked_pass, view_entity, item); | ||||||||||
} | ||||||||||
} | ||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -14,7 +14,9 @@ impl Node for MainPassDriverNode { | |||||
_render_context: &mut RenderContext, | ||||||
world: &World, | ||||||
) -> Result<(), NodeRunError> { | ||||||
let extracted_cameras = world.get_resource::<ExtractedCameraNames>().unwrap(); | ||||||
let extracted_cameras = world | ||||||
.get_resource::<ExtractedCameraNames>() | ||||||
.expect("Could not get `ExtractedCameraNames` resource from the `World`."); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if let Some(camera_2d) = extracted_cameras.entities.get(CameraPlugin::CAMERA_2D) { | ||||||
graph.run_sub_graph( | ||||||
crate::draw_2d_graph::NAME, | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In both those cases, the issue would be either:
AudioPlugin
Source
without having it set up first like inbevy/crates/bevy_audio/src/lib.rs
Lines 57 to 59 in 0ccb9dd
It could be helpful to explain how to fix the issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this be a case where adding to the error codes is best for an explanation?