Fix crash on unmapped key codes in onKeyEvent#1996
Closed
Juan-Antonio-Doe wants to merge 1 commit intobrunodev85:mainfrom
Closed
Fix crash on unmapped key codes in onKeyEvent#1996Juan-Antonio-Doe wants to merge 1 commit intobrunodev85:mainfrom
Juan-Antonio-Doe wants to merge 1 commit intobrunodev85:mainfrom
Conversation
Added a check to ignore unmapped key codes in onKeyEvent method to prevent crashes.
Game Genie (on Asus devices) may send invalid keycodes such as 851 or 861
during screen on/off events. This caused `Keyboard.onKeyEvent()` to index
`keys[keyCode]` out of bounds (`length=159, index=851`), leading to
`ArrayIndexOutOfBoundsException`.
#### Exception details
Extracted from a logcat generated with adb:
```
FATAL EXCEPTION: main
Process: com.winlator
java.lang.ArrayIndexOutOfBoundsException: length=159 index=851
at com.winlator.xserver.Keyboard.onKeyEvent(Keyboard.java:104)
Caused by: android.view.KeyEvent-JNI: java.lang.IllegalArgumentException: Invalid keycode 851
```
|
Sorry for posting here, but I couldn't find any other way to give feedback — there’s no contact form on the site and issues are disabled. I tested Winlator on a Xiaomi Mi Pad 4 (Snapdragon 660 / Adreno 512):
Just wanted to share this compatibility note for older devices. Hope it helps! |
|
Please fast |
|
Please improve |
Juan-Antonio-Doe
referenced
this pull request
in utkarshdalal/GameNative
Mar 23, 2026
* fix: prevent activity recreation due to connecting a mouse/keyboard * fix: allow mouse cursor to be shown * fix: changed keyboard behavior to match desktop experience * fix: prevent external mouse/keyboard from being recognized as gamepad * fix: do not allow view to be highlighted from disconnecting devices when Android is not in touch mode * fix/refactor: update touchpad code to use relative motion values from the device * fix/refactor: changed external device checks and on-screen gamepad UI detection * fix: call dedicated function instead * fix: wait to capture mouse only when container is unpaused * fix: prevent any keyboard/gamepad events from reaching the game while menus are open * revert touchpad relative movement changes * add SOURCE_TOUCHPAD in the mouse detection * fix: correctly separate keyboard and gamepads and remove additional hide on-screen controls once logic
Author
|
Reason for closure: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added a check to ignore unmapped key codes in onKeyEvent method to prevent crashes.
Game Genie (on Asus devices) may send invalid keycodes such as
851or861during screen on/off events. This causedKeyboard.onKeyEvent()to indexkeys[keyCode]out of bounds (length=159, index=851), leading toArrayIndexOutOfBoundsException.Exception details
Extracted from a logcat generated with
adb:I know this code/repository is old and doesn't include all the changes from your latest releases, but this bug is still present in those releases, so I hope you can include this in the next ones.