Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

replace all .single calls with matched .get_single calls #296

Merged
merged 3 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# UNRELEASED

- Fixed: replace all `.single` calls with matched `.get_single` calls to avoid crashing in
environments where there is no window available
- Fixed: sprite picking depth is now consistent with other picking backends.
- Fixed: entities with identical depth could be dropped due to the use of a BTreeMap to sort
entities by depth. This has been changed to use a sorted Vec, to allow entities with the same
Expand Down
5 changes: 4 additions & 1 deletion backends/bevy_picking_sprite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ pub fn sprite_picking(
.find(|(_, camera, _, _)| {
camera
.target
.normalize(Some(primary_window.single()))
.normalize(Some(match primary_window.get_single() {
Ok(w) => w,
Err(_) => return false,
}))
.unwrap()
== location.target
})
Expand Down
5 changes: 4 additions & 1 deletion backends/bevy_picking_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ pub fn ui_picking(
)
})
}) {
let window_entity = primary_window.single();
let window_entity = match primary_window.get_single() {
Ok(w) => w,
Err(_) => continue,
};

// Find the topmost bevy_ui camera with the same target as this pointer.
//
Expand Down
5 changes: 4 additions & 1 deletion crates/bevy_picking_core/src/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,10 @@ impl Location {
) -> bool {
if camera
.target
.normalize(Some(primary_window.single()))
.normalize(Some(match primary_window.get_single() {
Ok(w) => w,
Err(_) => return false,
}))
.as_ref()
!= Some(&self.target)
{
Expand Down
8 changes: 7 additions & 1 deletion crates/bevy_picking_input/src/mouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ pub fn mouse_pick_events(
PointerId::Mouse,
Location {
target: RenderTarget::Window(WindowRef::Entity(event.window))
.normalize(Some(windows.single().0))
.normalize(Some(
match windows.get_single() {
Ok(w) => w,
Err(_) => continue,
}
.0,
))
.unwrap(),
position: event.position,
},
Expand Down
8 changes: 7 additions & 1 deletion crates/bevy_picking_input/src/touch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ pub fn touch_pick_events(
let pointer = PointerId::Touch(touch.id);
let location = Location {
target: RenderTarget::Window(WindowRef::Primary)
.normalize(Some(windows.single().0))
.normalize(Some(
match windows.get_single() {
Ok(w) => w,
Err(_) => continue,
}
.0,
))
.unwrap(),
position: touch.position,
};
Expand Down
Loading