Skip to content

Fix crash on unmapped key codes in onKeyEvent#1996

Closed
Juan-Antonio-Doe wants to merge 1 commit intobrunodev85:mainfrom
Juan-Antonio-Doe:patch-1
Closed

Fix crash on unmapped key codes in onKeyEvent#1996
Juan-Antonio-Doe wants to merge 1 commit intobrunodev85:mainfrom
Juan-Antonio-Doe:patch-1

Conversation

@Juan-Antonio-Doe
Copy link
Copy Markdown

@Juan-Antonio-Doe Juan-Antonio-Doe commented Feb 22, 2026

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

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.

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
```
@Lightmorer
Copy link
Copy Markdown

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):

  • Winlator 10.0 launches successfully
  • Winlator 10.1 and above immediately crash
  • Working configuration: VirGL (Universal) + WineD3D, 1280x800 resolution
  • Tested with Space Rangers HD War Apart (latest version)

Just wanted to share this compatibility note for older devices. Hope it helps!

@Jeney6
Copy link
Copy Markdown

Jeney6 commented Feb 25, 2026

Please fast

@Jeney6
Copy link
Copy Markdown

Jeney6 commented Feb 25, 2026

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
@Juan-Antonio-Doe
Copy link
Copy Markdown
Author

Juan-Antonio-Doe commented Apr 15, 2026

Reason for closure:
New updated pull request where the code now seems to reside:
brunodev85/winlator-app#2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants