Skip to content

Commit e9a501e

Browse files
committed
Fixes potential panic when unwrapping touch event on Moved phase (#1591)
Should fix #1516. I don't have any devices available to test this tbh but I feel like this was the only spot that could be causing a panic. @ptircylinder since you posted this issue, could you please try to run the example on this branch and check if you get the same behavior while using your device? Thank you!
1 parent faeccd7 commit e9a501e

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

crates/bevy_input/src/touch.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,13 @@ impl Touches {
194194
self.just_pressed.insert(event.id, event.into());
195195
}
196196
TouchPhase::Moved => {
197-
let mut new_touch = self.pressed.get(&event.id).cloned().unwrap();
198-
new_touch.previous_position = new_touch.position;
199-
new_touch.previous_force = new_touch.force;
200-
new_touch.position = event.position;
201-
new_touch.force = event.force;
202-
self.pressed.insert(event.id, new_touch);
197+
if let Some(mut new_touch) = self.pressed.get(&event.id).cloned() {
198+
new_touch.previous_position = new_touch.position;
199+
new_touch.previous_force = new_touch.force;
200+
new_touch.position = event.position;
201+
new_touch.force = event.force;
202+
self.pressed.insert(event.id, new_touch);
203+
}
203204
}
204205
TouchPhase::Ended => {
205206
self.just_released.insert(event.id, event.into());

0 commit comments

Comments
 (0)