From 8d568344e399c7854d3aa2f4b374cdbe3429c76b Mon Sep 17 00:00:00 2001 From: Jochen Peters Date: Tue, 26 Jun 2018 23:38:22 +0200 Subject: [PATCH] fix in event.rs: safely unwrapping keyboard::Mod --- src/sdl2/event.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/sdl2/event.rs b/src/sdl2/event.rs index d32d947010f..b1f404984b4 100644 --- a/src/sdl2/event.rs +++ b/src/sdl2/event.rs @@ -1262,12 +1262,13 @@ impl Event { EventType::KeyDown => { let event = raw.key; + Event::KeyDown { timestamp: event.timestamp, window_id: event.windowID, keycode: Keycode::from_i32(event.keysym.sym as i32), scancode: Scancode::from_i32(event.keysym.scancode as i32), - keymod: keyboard::Mod::from_bits(event.keysym.mod_).unwrap(), + keymod: Event::unwrap_keymod(keyboard::Mod::from_bits(event.keysym.mod_)), repeat: event.repeat != 0 } } @@ -1607,6 +1608,13 @@ impl Event { }} // close unsafe & match } + pub fn unwrap_keymod(keymod_option: Option) -> keyboard::Mod { + match keymod_option { + None => keyboard::Mod::empty(), + Some(x) => x, + } + } + pub fn is_user_event(&self) -> bool { match *self { Event::User { .. } => true,