Controller listener + LwjglFrame causes crash
See original GitHub issueIssue details
While controllers are connected, attempting to add a controller listener in an app that also uses a LwjglFrame causes the error:
Error creating joystick: Win32JoyStick::_initialize() >> failed to set cooperation level!
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00000000621c3e13, pid=31304, tid=0x00000000000027f4
#
# JRE version: Java(TM) SE Runtime Environment (8.0_141-b15) (build 1.8.0_141-b15)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.141-b15 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C [gdx-controllers-desktop64.dll+0x3e13]
Reproduction steps/code
It’s a little hard to isolate the code in my engine, but in a default project, start your game this way:
new LwjglFrame(new MyGDXGame(), cfg); //the configuration doesn't matter
At some point in your game’s code, attempt to add a controller listener.
Controllers.addListener(my_controller_listener);
The app will crash at this point with the above error if any controllers are connected. Unplugging the controllers before starting the app will cause the app to work properly.
If you start your game using LwjglApplication instead of LwjglFrame, it will start normally with no other changes necessary:
new LwjglApplication(new MyGDXGame(), cfg);
Version of LibGDX and/or relevant dependencies
1.9.10. It may affect earlier versions but I’m not sure.
Stacktrace
Have to type this myself as it doesn’t print out anywhere. I stepped through the GDX sources, and it crashes at OisJoystick.getButtonCount. The joystickPtr value of the OisJoystick is 0, which seems to me like it might be an invalid value but I’m not sure.
OisJoystick.getButtonCount() line: 91
OisJoystick.<init>(long, String) line: 40
Ois.<init>(long) line: 33
OisControllers.<init>(DesktopControllerManager) line: 44
DesktopControllerManager.<init>() line: 32
NativeConstructorAccessorImpl.newInstance()(Constructor<?>, Object[]) line: not available [native method]
NativeConstructorAccessorImpl.newInstance(Object[]) line: not available
DelegatingConstructorAccessorImpl.newInstance(Object[]) line: not available
Constructor<T>.newInstance(Object...) line: not available
Class<T>.newInstance() line: not available
ClassReflection.newInstance(Class<T>) line: 93
Controllers.initialize() line: 118
Controllers.addListener(ControllerListener) line: 59
Please select the affected platforms
- Android
- iOS (robovm)
- iOS (MOE)
- HTML/GWT
- Windows
- Linux
- MacOS
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
Just wanted to update- I did end up moving to Jamepad. I’m very happy with it so far, and moving to it was painless. Rumble support and hotplugging is awesome, and I’d second your recommendation to use Jamepad for anyone running into this issue.
Hi, please take a look at gdx-controllers v2 prerelease snapshot. It’s powered by Jamepad.