From e9a501e6b8f95d1e7b4b803750f4ee85475c1c36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Maita?= <47983254+mnmaita@users.noreply.github.com> Date: Wed, 10 Mar 2021 00:44:45 +0000 Subject: [PATCH] Fixes potential panic when unwrapping touch event on Moved phase (#1591) Should fix https://github.com/bevyengine/bevy/issues/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! --- crates/bevy_input/src/touch.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/bevy_input/src/touch.rs b/crates/bevy_input/src/touch.rs index 07ec595185..9961a084ee 100644 --- a/crates/bevy_input/src/touch.rs +++ b/crates/bevy_input/src/touch.rs @@ -194,12 +194,13 @@ impl Touches { self.just_pressed.insert(event.id, event.into()); } TouchPhase::Moved => { - let mut new_touch = self.pressed.get(&event.id).cloned().unwrap(); - new_touch.previous_position = new_touch.position; - new_touch.previous_force = new_touch.force; - new_touch.position = event.position; - new_touch.force = event.force; - self.pressed.insert(event.id, new_touch); + if let Some(mut new_touch) = self.pressed.get(&event.id).cloned() { + new_touch.previous_position = new_touch.position; + new_touch.previous_force = new_touch.force; + new_touch.position = event.position; + new_touch.force = event.force; + self.pressed.insert(event.id, new_touch); + } } TouchPhase::Ended => { self.just_released.insert(event.id, event.into());