ControllerListeners ineffective ?

Hi,

I’m trying to use JInput2 (jinput_combined_dist_20060514) in an emulator project on Windows XP, but I’m currently experiencing some problems related to ControllerListeners : For some unknown reason, it seems that the ControllerListener I registered never get notified about added/removed controllers.

Moreover, the array returned by the getControllers() method is never updated (when I unplug a controller, it’s still returned in this array, although the controller cannot be polled anymore - even if I plug it back )

For instance, when I run the following test case with, say, 2 controllers connected, then unplug one (or plug a new one), I get “Available controllers count : 2” print once, and nothing else…

import net.java.games.input.*;

public class TestListener 
{
    static public void main( String[] args )
    {
        ControllerEnvironment env = ControllerEnvironment.getDefaultEnvironment();

        env.addControllerListener( new ControllerListener() {
            public void controllerRemoved( ControllerEvent e ) { System.out.println("REMOVED"); }
            public void controllerAdded  ( ControllerEvent e ) { System.out.println("ADDED"  ); }
        });

        int count = -1;

        for(;;) {
            int update = env.getControllers().length;
            if (count != update) {
                count = update;
                System.out.println( "Available controllers count : " + count );
            }
            try { Thread.sleep(200); } catch( InterruptedException e ) { /*empty*/ }
        }
    }
}

Did I do something wrong?

Thanks!

You didn’t do anything wrong, they just arn’t implemented at the last check.

HTH

Endolf

Oh all right, no wonder then… :slight_smile:
Thanks for the info, Endolf!

By the way, I was wondering if Jinput2 was still an active project, or if it has been discontinued?

It’s active in as much as if there is things people want/need, that make sence, it generally happens. Late last year I wrote a new plug in that was requested for example. I check the forums here several times each day, and any issues raised in the issue tracker on jinput.dev.java.net I get emailed and look at.

Elias seems to be using jinput activly at the moment, and seems to be spotting the odd thing here and there, and fixese them and checks them in, december was his last checkin.

There are a number of other folks using it too, it’s in lwjgl and jME too.

As far as I am aware, at this moment in time, there are no major features being worked on, but that is a reflection of the requests we’ve had, rather than a reflection of interest from the devs.

Endolf

Good, glad to hear it’s still being updated, as it’s clearly the java API of choice to access controllers !

If I happen to find some strange behaviour I’ll post them here in the future, it might be of use, then… :slight_smile:

Well, actually, I already got an exception yesterday while playing with the library yesterday ; and from the top of my head it looks like the same problem as desribed in this thread : NullPointerException thrown from Poll() method (I’d have to check the exception stack to be sure).

Is this issue resolved in the last checkin yet?
If not, maybe I could be of use and provide you with any extra info / tests that could help regarding the problem ?

Cheers,
Franck.

I commited a fix way back in may last year for that, but never heard anything back from the person who reported it, so I don’t know if it worked. Can you post your symptoms and stack trace in a new thread here and I’ll take a look.

Can you also let me know if the jinput tests work, or do they fail too?

Thanks

Endolf

Ok, I’ll check this evening and post the result.

Franck.

All right, things are clear now…

After several tests, I finally noticed that the fix you were talking about was not included into the build I used (the latest available : jinput_combined_dist_20060514), since I got exactly the same exception as described in the other thread (when using the jinput test class) :


java.lang.NullPointerException
	at net.java.games.input.DIControllers.getNextDeviceEvent(DIControllers.java:62)
	at net.java.games.input.DIAbstractController.getNextDeviceEvent(DIAbstractController.java:62)
	at net.java.games.input.AbstractController.poll(AbstractController.java:219)
	at net.java.games.input.test.ControllerWindow.poll(ControllerReadTest.java:230)
	at net.java.games.input.test.ControllerReadTest$1.run(ControllerReadTest.java:269)
	at java.lang.Thread.run(Unknown Source)

So I checkout the latest version from CVS and compiled it, and the NPE is not here anymore !
Thus I can confirm that your fix works properly. :slight_smile:

I was just not using the latest sources… My bad, sorry.

Thanks for your time,
Franck.

Looks like I need to do a new build and upload it :slight_smile:

The latest one was October 29th last year. That build should have worked.

Other things have gone in since then, so I ought to do one soon, maybe over the weekend.

Endolf

Indeed, it does.
I don’t know how I missed this one, sorry for the mess! :-[

No worries

Answering questions like this at least prove that the API is being used :slight_smile:

Answering questions like this is also alot easier than the technical ones :slight_smile:

Endolf

Has there been any progress on implementing this feature? I saw a post (can’t remember where) made this year (2009) asking which OS’s to give preference to. I’d love to see this implemented in Windows. The ability to handle as events removed or added controllers would be wonderful. Or at least re-implement ControllerEnvironment.getControllers() such that it returns an updated array of controllers. At present it appears to, on first execution, get the list of attached devices and then on all future calls return the same list regardless of any hardware changes (removing/adding controllers). I’ll happily code the listener and add it to the codebase once getControllers returns accurate information.

Thank you for this great library, many people are using it!

There was some work done (not by me), but they have been unable to release it as open source. So there is nothing we can use other than the experience I gained talking to them whilst helping get it working.

Endolf