libgdx / Jamepad

A better way to use gamepads in Java
Apache License 2.0
19 stars 11 forks source link

Excessive use of user objects on Windows #28

Closed breiler closed 6 months ago

breiler commented 6 months ago

When using the library (version 2.26.5.0, 2.26.4.0 and 2.0.20.0) on Windows it seems that it will start allocating "User Objects" which will finally make the application unresponsive. On Mac and Linux this works without problems.

The interesting thing is that if the window of the related process is not in focus it will not create new user objects even though the example is a console application:

https://github.com/libgdx/Jamepad/assets/8962024/de17f129-aaf3-454f-bd40-4dd74171f941

Example program:

package com.willwinder.ugs.nbp.joystick;

import com.studiohartman.jamepad.Configuration;
import com.studiohartman.jamepad.ControllerManager;
import com.studiohartman.jamepad.ControllerState;

public class TestMain {
    public static void main(String[] args) {
        Configuration configuration = new Configuration();
        ControllerManager controllerManager = new ControllerManager(configuration, "/com/willwinder/ugs/nbp/joystick/gamecontrollerdb.txt");
        controllerManager.initSDLGamepad();

        // Print a message when the "A" button is pressed. Exit if the "B" button is pressed
        // or the controller disconnects.
        while (true) {
            ControllerState currState = controllerManager.getState(0);

            if (!currState.isConnected || currState.b) {
                break;
            }
            if (currState.a) {
                System.out.println("\"A\" on \"" + currState.controllerType + "\" is pressed");
            }
        }
    }
}

Tried with JDK Temurin 17.0.9 and Temuring 21.0.2.

breiler commented 6 months ago

I built this locally and upgraded SDL to the latest release https://github.com/libsdl-org/SDL/tree/release-2.30.x and problem was no longer present.

breiler commented 6 months ago

Tried it on Linux x64, Windows x64 and MacOSX using the new dependency and at least the small test program works as before:

<dependency>
  <artifactId>jamepad</artifactId>
  <groupId>com.badlogicgames.jamepad</groupId>
  <version>2.30.0.0-SNAPSHOT</version>
</dependency>

The problem with user objects are no longer present: https://github.com/libgdx/Jamepad/assets/8962024/953b1281-b984-48d0-8475-4c8f6b83f3f1