gurkenlabs / litiengine

LITIENGINE 🕹 The pure 2D java game engine.
https://litiengine.com/
MIT License
725 stars 93 forks source link

Newly added gamepad has ID which is out of bounds of gamepad manager's internal array. #431

Closed ecchilds closed 2 years ago

ecchilds commented 2 years ago

Describe the bug Index of a newly added gamepad was out of bounds. Was likely due to a failure to add other gamepads, which did not exist, but which were still picked up by the app. Specifically, a Huion Pentablet driver seemed to ping the gamepad manager, likely incrementing the default gamepad index without actually adding to the manager's gamepad array.

Notably, this does not crash the game, but it does make gamepads unusable.

Stack Trace

Dec 23, 2021 6:15:19 PM de.gurkenlabs.litiengine.UpdateLoop update
SEVERE: Index 2 out of bounds for length 1
java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 1
    at java.base/java.util.concurrent.CopyOnWriteArrayList.elementAt(CopyOnWriteArrayList.java:385)
    at java.base/java.util.concurrent.CopyOnWriteArrayList.get(CopyOnWriteArrayList.java:398)
    at de.gurkenlabs.litiengine.input.GamepadManager.get(GamepadManager.java:164)
    at de.gurkenlabs.litiengine.input.GamepadEntityController.retrieveGamepadValues(GamepadEntityController.java:76)
    at de.gurkenlabs.litiengine.input.GamepadEntityController.update(GamepadEntityController.java:43)
    at de.gurkenlabs.litiengine.UpdateLoop.update(UpdateLoop.java:154)
    at de.gurkenlabs.litiengine.UpdateLoop.process(UpdateLoop.java:138)
    at de.gurkenlabs.litiengine.GameLoop.process(GameLoop.java:86)
    at de.gurkenlabs.litiengine.UpdateLoop.run(UpdateLoop.java:57)

Probably related error message:

Dec 23, 2021 6:15:00 PM net.java.games.input.ControllerEnvironment log
INFO: Failed to initialize device HUION HID because of: java.io.IOException: Failed to acquire device (8007001e)

To Reproduce (Probable) steps to reproduce the behavior:

  1. Install (very old) Huion H610pro pentablet drivers.
  2. Run application within IDE.
  3. Connect Gamepad controller.

Expected behavior Index of new Gamepad should be within bounds.

Your System:

Additional context Notably, this still occurs even when the pentablet drivers are not running. It is possible the pentablet drivers are not a part of this issue, I am still not sure. I will update this thread if I get further information.

Gamebuster19901 commented 2 years ago

This might have been resolved in c31fffdfc521682e0a31f68cdc28bed929a030e4, not sure though.

Gamebuster19901 commented 2 years ago

Specifically, the issue might be caused because Input.gamepads().get() was being called instead of Input.gamepads().getByID() https://github.com/gurkenlabs/litiengine/blob/402bafac346b595c159b6eaf1b4b88fd811219f0/src/de/gurkenlabs/litiengine/input/GamepadEntityController.java#L76-L77

ecchilds commented 2 years ago

Ah, yeah, that does look like it would fix it. I guess I should update. Thanks for the help!

Gamebuster19901 commented 2 years ago

I don't believe a version that has that commit and is buildable is available yet.

ecchilds commented 2 years ago

Welp, I ended up fixing it by implementing a near carbon copy of GamepadEntityController with the changes from that commit.

nightm4re94 commented 2 years ago

We're planning to release v0.5.2 next week, thanks for standing by and merry Christmas!

steffen-wilke commented 2 years ago

Fixed in c31fffdfc521682e0a31f68cdc28bed929a030e4