Skip to content

Commit

Permalink
Fixes potential panic when unwrapping touch event on Moved phase (bev…
Browse files Browse the repository at this point in the history
…yengine#1591)

Should fix bevyengine#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!
  • Loading branch information
mnmaita committed Mar 10, 2021
1 parent faeccd7 commit e9a501e
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions crates/bevy_input/src/touch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit e9a501e

Please sign in to comment.