[SOLVED] JoystickConnectionListener not working

I am newbie with JMonkeyEngine 3.6 and i am learning with the tutorials.

I am successfully using a Gamepad F310 button, but the connect/disconnect listener is not working :
hello_input (listening-for-joystick-connections)

When i unplug the gamepad, i get this looped message in console:

INFOS: Failed to poll device: Failed to poll device (8007000c)

Can you help me please ?

Note that JoystickConnectionListener only works in LWJGL3, as discussed here:

Thanks for the quick reply.

How do I know if I am in LWJGL3 ?
Is this the value returned by the settings.getRenderer() method ? In my application, the returned value is LWJGL-OpenGL3. Am i in LWJGL3 ?

By looking at your project dependencies.

When you setup the project, you set which version of lwjgl you use by which of the JME libraries you pick (or it was set for you). We donā€™t know how youā€™ve set your project up and so canā€™t really provide a more detailed response than that.

1 Like

OK, I think youā€™re talking about JME IDE.
In fact, i use directly the JME 3.6 libraries with Eclipse IDE. So I will use JME IDE and i will come back to you later.
Thanks!

Then check which of these libraries youā€™re using:

  • jme3-lwjgl-3.6.0-stable.jar ā€”> LWJGL2
  • jme3-lwjgl3-3.6.0-stable.jar ā€”> LWJGL3
2 Likes

This file is not in the library I downloaded from github :
https://github.com/jMonkeyEngine/jmonkeyengine/releases
I choose jME3.6.1-stable.zip.

Inside, i am a file lib\jme3-lwjgl.jar.

While not really about your particular problem. You should move fromā€¦ Ant? to Gradle. It will be much easier in the long run. You donā€™t need to manage dependencies by hand. Or even partner Apache Ivy with Ant thenā€¦ Well, totally recommend to skip that and go straight to Gradle.

Since you want to use Eclipse, jMonkeyEngine | Quick Start, use that to get your Gradle project going.

OK. Iā€™ll use Gradle, hoping the dependencies are the right ones. Iā€™ll come back later.

Thanks for your interest in my problem.

1 Like

I downloaded the gradle project created with your online tool. I imported the project into Eclipse. But JoystickConnectionListener is still causing an error in the console when I unplug the GamePad.

According to your information, if I get these error messages in the console with JoystickConnectionListener, itā€™s because the library uses LWJGL2 and not LWJGL3. Is this correct? Please tell me if Iā€™m wrong.

I have tried successfully :

  1. To download (from Github) the Java archives used with Eclipse
  2. To use the JME SDK IDE (without Eclipse)
  3. Import a Gradle project with Eclipse

But i always get the same error with JoystickConnectionListener.

How to access a distribution that uses LWJGL3 (for a desktop application) ?

The code i use :

public class Test extends SimpleApplication {

    public static void main(String[] args) {
        Test app = new Test();
        app.setShowSettings(false);
        AppSettings appSettings = new AppSettings(true);
        appSettings.setUseJoysticks(true);
		app.setSettings(appSettings);
        app.start();
    }

    @Override
    public void simpleInitApp() {
        Box b = new Box(1, 1, 1);
        Geometry geom = new Geometry("Box", b);
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.setColor("Color", ColorRGBA.Blue);
        geom.setMaterial(mat);
        rootNode.attachChild(geom);
        
        inputManager.addJoystickConnectionListener(new JoystickConnectionListener() {
            @Override
            public void onConnected(Joystick joystick) {
                System.out.println("Joystick connected: " + joystick.getName());
            }
            @Override
            public void onDisconnected(Joystick joystick) {
                System.out.println("Joystick Disconnected: " + joystick.getName());
            }
        });
    }

}

Can you post your build.gradle file? That will answer a lot of questions that folks trying to help will have.

1 Like

ā€œbuild.gradleā€ file :

plugins {
    id 'application'
    id 'java'
    id "de.undercouch.download" version "5.1.0"
    id 'idea'
    id "io.github.0ffz.github-packages" version "1.2.1" // Plugin for anonymous inclusion of artifacts hosted in github package registry
}

description = 'CubeGame application'

java {
    sourceCompatibility = '17'
    targetCompatibility = '17'
}

ext.jmonkeyengineVersion = '3.6.1-stable'

mainClassName = 'barna.cubegame.CubeGame'
if (!hasProperty('mainClass')) {
    ext.mainClass = mainClassName
}
jar.manifest.attributes('Main-Class': mainClassName)

repositories {
    maven githubPackage.invoke("riccardobl/undefined")
    maven { url "https://jitpack.io" }
    mavenCentral()
    mavenLocal()
}

application {
    if (System.getProperty("os.name").toLowerCase().contains("mac")) {
        applicationDefaultJvmArgs = ['-XstartOnFirstThread'] // this is when using a Mac as a development machine which requires the AppKit main UI thread to be used for GUI applications
    }
}

dependencies {
    // You can read more about how to add dependencies here:
    //   https://docs.gradle.org/current/userguide/dependency_management.html#sec:how_to_declare_your_dependencies

    implementation 'org.jmonkeyengine:jme3-core:' + jmonkeyengineVersion
    implementation 'org.jmonkeyengine:jme3-desktop:' + jmonkeyengineVersion
    runtimeOnly 'org.jmonkeyengine:jme3-jogg:' + jmonkeyengineVersion
    runtimeOnly 'org.jmonkeyengine:jme3-plugins:' + jmonkeyengineVersion

    implementation 'org.jmonkeyengine:jme3-niftygui:' + jmonkeyengineVersion
    implementation 'org.jmonkeyengine:jme3-effects:' + jmonkeyengineVersion
    implementation 'org.jmonkeyengine:jme3-terrain:' + jmonkeyengineVersion
    implementation 'org.jmonkeyengine:jme3-jbullet:' + jmonkeyengineVersion
    runtimeOnly 'org.jmonkeyengine:jme3-lwjgl3:' + jmonkeyengineVersion

    implementation 'com.github.Jeddic:particlemonkey:1.0.2'
    implementation 'com.github.joliver82:jme3-wireframe:1.0.2'
    implementation 'net.aaaagames:PBRTerrain:1.0.2'
    implementation 'com.github.stephengold:Wes:0.7.2'
    implementation 'com.github.stephengold:Heart:8.6.0'
    implementation 'org.apache.logging.log4j:log4j-core:2.24.0'
    implementation 'org.apache.logging.log4j:log4j-api:2.24.0'
    implementation 'com.rvandoosselaer:blocks:1.7.0'
    implementation 'com.github.grizeldi:HoloShader:-SNAPSHOT'
    implementation 'com.github.riccardobl.DDSWriter:dds_writer:1.3.2'
    implementation 'com.github.stephengold:Minie:7.7.0'
    implementation 'com.simsilica:lemur:1.16.0'
    implementation 'com.simsilica:lemur-proto:1.13.0'
    implementation 'wf.frk:jme-igui:0.1.2'
}

distZip {
    //having a degenerate folder within the dist zip complicates generating the other zips
    eachFile { file ->
        String path = file.relativePath
        file.setPath(path.substring(path.indexOf("/") + 1, path.length()))
    }
    includeEmptyDirs(false)
}

//See https://api.adoptium.net/v3/assets/feature_releases/11/ga?image_type=jre for jre urls
def windowsJreUrl = "https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.6%2B10/OpenJDK17U-jre_x64_windows_hotspot_17.0.6_10.zip"
def linuxJreUrl = "https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.6%2B10/OpenJDK17U-jre_x64_linux_hotspot_17.0.6_10.tar.gz"
def macJreUrl = "https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.6%2B10/OpenJDK17U-jre_x64_mac_hotspot_17.0.6_10.tar.gz"


task downloadWindowsJre(type: Download) {
    src windowsJreUrl
    dest new File(buildDir, '/jres/windowsJre.zip')
    overwrite false
}

task downloadAndUnzipWindowsJre(dependsOn: downloadWindowsJre, type: Copy) {
    from zipTree(downloadWindowsJre.dest)
    into "${buildDir}/jres/windowsJre/"
    includeEmptyDirs(false)
    filesMatching("**") {
        it.path = it.path.replaceAll("^[a-zA-Z0-9.+-]*[/\\\\]", "jre/") //rename the top level to something standard so the rest of the script will be easier
    }
}

task buildWindowsDistribution(dependsOn: [distZip, downloadAndUnzipWindowsJre], type: Copy)
{
    group 'distribution'
    from files("${projectDir}/scripts/desktopDeployment/CubeGame.bat"), zipTree(distZip.archiveFile), "${buildDir}/jres/windowsJre"
    into new File(buildDir, 'distributions/CubeGame-windows')
    includeEmptyDirs false
    exclude 'bin/**' //we are adding our own run scripts, exclude the ones coming from distZip
}

task zipWindowsDistribution( dependsOn:buildWindowsDistribution, type: Zip) {
    group 'distribution'
    archiveFileName = "CubeGame-windows.zip"
    destinationDirectory = file("$buildDir/distributions")
    from "$buildDir/distributions/CubeGame-windows"
}


task downloadLinuxJre(type: Download) {
    src linuxJreUrl
    dest new File(buildDir, '/jres/linuxJre.tar.gz')
    overwrite false
}

task downloadAndUnzipLinuxJre(dependsOn: downloadLinuxJre, type: Copy) {
    from tarTree(downloadLinuxJre.dest)
    into "${buildDir}/jres/linuxJre/"
    includeEmptyDirs(false)
    filesMatching("**") {
        it.path = it.path.replaceAll("^[a-zA-Z0-9.+-]*[/\\\\]", "jre/") //rename the top level to something standard so the rest of the script will be easier
    }
}

task buildLinuxDistribution(dependsOn: [distZip, downloadAndUnzipLinuxJre], type: Copy)
{
    group 'distribution'
    from files("${projectDir}/scripts/desktopDeployment/CubeGame.sh"){
        fileMode 0755
    }
    from zipTree(distZip.archiveFile)
    from "${buildDir}/jres/linuxJre"
    into new File(buildDir, 'distributions/CubeGame-linux')
    includeEmptyDirs false
    exclude 'bin/**' //we are adding our own run scripts, exclude the ones coming from distZip
}

task zipLinuxDistribution( dependsOn:buildLinuxDistribution, type: Zip) {
    group 'distribution'
    archiveFileName = "CubeGame-linux.tar.gz"
    destinationDirectory = file("$buildDir/distributions")
    from ("$buildDir/distributions/CubeGame-linux"){
      include('**.sh')
      include('**/java')
      fileMode 0755
    }
    from ("$buildDir/distributions/CubeGame-linux"){
        exclude('**.sh')
        exclude('**/java')
    }
}


task downloadMacJre(type: Download) {
    src macJreUrl
    dest new File(buildDir, '/jres/macJre.tar.gz')
    overwrite false
}

task downloadAndUnzipMacJre(dependsOn: downloadMacJre, type: Copy) {
    from tarTree(downloadMacJre.dest)
    into "${buildDir}/jres/macJre/"
    includeEmptyDirs(false)
    filesMatching("**") {
        it.path = it.path.replaceAll("^[a-zA-Z0-9.+-]*[/\\\\]", "jre/") //rename the top level to something standard so the rest of the script will be easier
    }
}

task buildMacDistribution(dependsOn: [distZip, downloadAndUnzipMacJre], type: Copy)
{
    group 'distribution'
    from files("${projectDir}/scripts/desktopDeployment/CubeGame.command"){
        fileMode 0755
    }
    from zipTree(distZip.archiveFile) 
    from "${buildDir}/jres/macJre"
    into new File(buildDir, 'distributions/CubeGame-mac')
    includeEmptyDirs false
    exclude 'bin/**' //we are adding our own run scripts, exclude the ones coming from distZip
}

task zipMacDistribution( dependsOn:buildMacDistribution, type: Zip) {
    group 'distribution'
    archiveFileName = "CubeGame-mac.tar.gz"
    destinationDirectory = file("$buildDir/distributions")
    from ("$buildDir/distributions/CubeGame-mac"){
      include('**.command')
      include('**/java')
      fileMode 0755
    }
    from ("$buildDir/distributions/CubeGame-mac"){
        exclude('**.command')
        exclude('**/java')
    }
}

task buildAllDistributions{
    group 'distribution'
    dependsOn 'zipWindowsDistribution'
    dependsOn 'zipLinuxDistribution'
    dependsOn 'zipMacDistribution'

    doLast {
        println("Distributions created in build/distributions folder")
    }
}

// cleanup tasks
clean.dependsOn('cleanDLLs', 'cleanDyLibs', 'cleanLogs', 'cleanSOs')
task cleanDLLs(type: Delete) {
    delete fileTree(dir: '.', include: '*.dll')
}
task cleanDyLibs(type: Delete) {
    delete fileTree(dir: '.', include: '*.dylib')
}
task cleanLogs(type: Delete) {
    delete fileTree(dir: '.', include: 'hs_err_pid*.log')
}
task cleanSOs(type: Delete) {
    delete fileTree(dir: '.', include: '*.so')
}

task fund(){
    doLast {
       java.awt.Desktop.desktop.browse "https://start.jmonkeyengine.org/#!funding=JME_DESKTOP,8113%2F189b56af-a1be-4036-8ac7-2b62a94935ff,2466%2Fb37a302d-261d-4823-8208-6b9b45595801,22975%2F2930932e-7688-493a-ad00-bc473df0f076,11511%2F15054f52-c439-4bfb-9a73-80260b486333,11511%2Fe534fc1e-5b78-46b7-a831-d5d40cbd9dcd,LOG4J2,16130%2F1a85df6f-4bb6-4c85-9e77-b5119662ed54,16912%2F435ebd61-fbbc-4e10-a490-234c222b4312,16283%2FDDSWriter,11511%2F38308161-c3cf-4e23-8754-528ca8387c11,LEMUR,16283%2Fjme-igui,JME_NIFTY,JME_EFFECTS,JME_TERRAIN,JME_JBULLET".toURI()
    }
}

Nota : I also have 2 errors :
Unresolved dependency: com.rvandoosselaer:blocks:1.7.0
Unresolved dependency: net.aaaagames:PBRTerrain:1.0.2

Your project should be using LWJGL 3 now.

So why do I get an error when I use a JoystickConnectionListener ?

Is it the same exact error message you are getting? And please post the startup log from your application that we can be absolutely sure you are on LWJGL 3

Yes, i see. Itā€™s LWJGL 2.9.5 !?!

From gradle project console log :

sept. 25, 2024 7:46:18 PM com.jme3.system.JmeDesktopSystem initialize
INFOS: Running on jMonkeyEngine 3.7.0-beta1.2.2
 * Branch: HEAD
 * Git Hash: 5cadb88
 * Build Date: 2024-07-30
sept. 25, 2024 7:46:19 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFOS: LWJGL 2.9.5 context running on thread jME3 Main
 * Graphics Adapter: null
 * Driver Version: null
 * Scaling Factor: 1
sept. 25, 2024 7:46:19 PM com.jme3.renderer.opengl.GLRenderer loadCapabilitiesCommon
INFOS: OpenGL Renderer Information
 * Vendor: NVIDIA Corporation
 * Renderer: NVIDIA GeForce GT 710/PCIe/SSE2
 * OpenGL Version: 3.2.0 NVIDIA 475.14
 * GLSL Version: 1.50 NVIDIA via Cg compiler
 * Profile: Core
sept. 25, 2024 7:46:19 PM net.java.games.input.DefaultControllerEnvironment getControllers
AVERTISSEMENT: Found unknown Windows version: Windows 11
sept. 25, 2024 7:46:19 PM net.java.games.input.DefaultControllerEnvironment getControllers
AVERTISSEMENT: Attempting to use default windows plug-in.
sept. 25, 2024 7:46:19 PM com.jme3.audio.openal.ALAudioRenderer initOpenAL
INFOS: Audio Renderer Information
 * Device: OpenAL Soft
 * Vendor: OpenAL Community
 * Renderer: OpenAL Soft
 * Version: 1.1 ALSOFT 1.15.1
 * Supported channels: 64
 * ALC extensions: ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE ALC_EXT_DEDICATED ALC_EXT_disconnect ALC_EXT_EFX ALC_EXT_thread_local_context ALC_SOFT_loopback
 * AL extensions: AL_EXT_ALAW AL_EXT_DOUBLE AL_EXT_EXPONENT_DISTANCE AL_EXT_FLOAT32 AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS AL_EXT_MULAW AL_EXT_MULAW_MCFORMATS AL_EXT_OFFSET AL_EXT_source_distance_model AL_LOKI_quadriphonic AL_SOFT_buffer_samples AL_SOFT_buffer_sub_data AL_SOFTX_deferred_updates AL_SOFT_direct_channels AL_SOFT_loop_points AL_SOFT_source_latency
sept. 25, 2024 7:46:19 PM com.jme3.audio.openal.ALAudioRenderer initOpenAL
AVERTISSEMENT: Pausing audio device not supported.
sept. 25, 2024 7:46:19 PM com.jme3.audio.openal.ALAudioRenderer initOpenAL
INFOS: Audio effect extension version: 1.0
sept. 25, 2024 7:46:19 PM com.jme3.audio.openal.ALAudioRenderer initOpenAL
INFOS: Audio max auxiliary sends: 4

From Jars from Github+Eclipse project console log :

sept. 25, 2024 7:56:13 PM com.jme3.system.JmeDesktopSystem initialize
INFOS: Running on jMonkeyEngine 3.6.1-stable
 * Branch: HEAD
 * Git Hash: 4de10c3
 * Build Date: 2023-06-23
sept. 25, 2024 7:56:14 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFOS: LWJGL 2.9.5 context running on thread jME3 Main
 * Graphics Adapter: null
 * Driver Version: null
 * Scaling Factor: 1
sept. 25, 2024 7:56:14 PM com.jme3.renderer.opengl.GLRenderer loadCapabilitiesCommon
INFOS: OpenGL Renderer Information
 * Vendor: NVIDIA Corporation
 * Renderer: NVIDIA GeForce GT 710/PCIe/SSE2
 * OpenGL Version: 3.2.0 NVIDIA 475.14
 * GLSL Version: 1.50 NVIDIA via Cg compiler
 * Profile: Core
sept. 25, 2024 7:56:14 PM net.java.games.input.DefaultControllerEnvironment getControllers
AVERTISSEMENT: Found unknown Windows version: Windows 11
sept. 25, 2024 7:56:14 PM net.java.games.input.DefaultControllerEnvironment getControllers
AVERTISSEMENT: Attempting to use default windows plug-in.
sept. 25, 2024 7:56:14 PM com.jme3.audio.openal.ALAudioRenderer initOpenAL
INFOS: Audio Renderer Information
 * Device: OpenAL Soft
 * Vendor: OpenAL Community
 * Renderer: OpenAL Soft
 * Version: 1.1 ALSOFT 1.15.1
 * Supported channels: 64
 * ALC extensions: ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE ALC_EXT_DEDICATED ALC_EXT_disconnect ALC_EXT_EFX ALC_EXT_thread_local_context ALC_SOFT_loopback
 * AL extensions: AL_EXT_ALAW AL_EXT_DOUBLE AL_EXT_EXPONENT_DISTANCE AL_EXT_FLOAT32 AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS AL_EXT_MULAW AL_EXT_MULAW_MCFORMATS AL_EXT_OFFSET AL_EXT_source_distance_model AL_LOKI_quadriphonic AL_SOFT_buffer_samples AL_SOFT_buffer_sub_data AL_SOFTX_deferred_updates AL_SOFT_direct_channels AL_SOFT_loop_points AL_SOFT_source_latency
sept. 25, 2024 7:56:14 PM com.jme3.audio.openal.ALAudioRenderer initOpenAL
AVERTISSEMENT: Pausing audio device not supported.
sept. 25, 2024 7:56:14 PM com.jme3.audio.openal.ALAudioRenderer initOpenAL
INFOS: Audio effect extension version: 1.0
sept. 25, 2024 7:56:14 PM com.jme3.audio.openal.ALAudioRenderer initOpenAL
INFOS: Audio max auxiliary sends: 4

Error with Gradle project :

sept. 25, 2024 7:50:10 PM net.java.games.input.ControllerEnvironment log
INFOS: Failed to poll device: Failed to poll device (8007000c)

Error with Jars from Github+Eclipse project :

sept. 25, 2024 7:51:42 PM net.java.games.input.ControllerEnvironment log
INFOS: Failed to poll device: Failed to poll device (8007000c)
2 Likes

Wherever thatā€™s coming from, it is definitely NOT the build.gradle file that you posed.

Of course , it is !!! I only have one ā€˜gradleā€™ project. Itā€™s not a mistake.

The gradle project obtained from https://jmonkeyengine.org/start/ and imported with Eclipse 2024-06 (4.32) !

But does Eclipse treat it as a Gradle project or did you have the old Ant stuff there to mess with Eclipse?

Or try running your project from the command line with gradlew run. Hopefully you have this file.

You may have a lot of reasons to BELIEVE thatā€™s the gradle file you are runningā€¦ but it is 100% not the gradle file that you are running.

It says you are using 3.7.0-beta1.2.2 of JME with lwjgl2.

But your build.gradle file says:

And:

Ergo, not the same build.gradle file that is being used to run.

(Also, I sort of would expect the gradle output to look different so I think you might still be running ANT as tonihele suggests.)

I know for sure that you are not using that build.gradle file, for whatever reason.