-
Notifications
You must be signed in to change notification settings - Fork 480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix proposal: safe unwrap of keyboard::Mod #780
Conversation
That's interesting. Which keys did you press that made it panic? I'm happy to merge this, but I would like to know how you discovered this issue, might give us a clue on something else. AFAIK rust-sdl2 is used quite a lot and this is the first time I've heard of such an issue, so this is surprising. |
@emirpnet Small tip for cleaner rust code, but you could have done
Would you mind telling us how did you discover this issue exactly? |
@Cobrand Thanks for the coding tip with the one-liner. The code that panicked is the one decribed here: http://pramode.in/2016/10/12/conway-game-of-life-rust-sdl2/ (I followed it along to learn about rust-sdl. Regarding key events, that code only handles the Escape-Key to quit the program.) |
For me, it occurs (in sdl2 versions before this fix) on
Hmm, 32766 is "all bits except least significant set", I can't see value for this in |
After adding Debug derive for
|
Maybe sdl is free to set remaining bits, for which there's no |
@kolen can you open another issue with the exact problem there? I have quite a hard time understanding what is wrong here |
I had some trouble with panics caused by the unwrap of the keymod on the KeyDown event and changed the code to default to keyboard::Mod::empty().
To me that makes sense and solved the issue, but I am aware that in general this behavior might not be wanted.