Hello,
I have a strange issue when I attempt to detect input devices; specifically I want to detect a gamepad when it is connected. To do this I have the following code:
private boolean connectGamePad(){
Controller[] ca;
DirectAndRawInputEnvironmentPlugin DARIEP = new DirectAndRawInputEnvironmentPlugin(); //Rebuild list of connected devices
ca = DARIEP.getControllers(); //Acquire device list
for(int i = 0; i < ca.length; i ++){
if(ca[i].getType().equals(Controller.Type.GAMEPAD))
{ // Acquire the first instance of a gamepad.
gamepad = ca[i];
gamepadButtons = gamepad.getComponents();
return true;
}
}
return false;
}
This function is invoked repeatetly untill it returns true, meaning it will attempt to find a gamepad untill one is connected. This works flawlessly for the first several minutes while my program is running, and will detect a gamepad if it is connected after the program is started.
However, after several minutes, JInput starts printing an error and will no longer detect a gamepad if this is connected to the PC while the program is executing. The error can be seen below.
sep. 06, 2017 9:22:13 AM net.java.games.input.ControllerEnvironment log
INFO: Failed to enumerate devices: Failed to create window (1158)
sep. 06, 2017 9:22:13 AM net.java.games.input.ControllerEnvironment log
INFO: Failed to enumerate devices: Failed to create window (1158)
As far as I can figure, the error is printed when I run the following line
DirectAndRawInputEnvironmentPlugin DARIEP = new DirectAndRawInputEnvironmentPlugin();
Any idea of what is causing this would be appreciated. Thanks in advance