Skip to content

[Solved ?] Memory leak when updating gamepad detection during Runtime #78

Open

Description

@sunsigne

In order to update gamepad detection during runtime (as Jinput doesn't), I created a "class patch" to periodicaly nullify registered controllers in DefaultControllerEnvironment class, using reflection.

The code is quite effecive : if I unplug - replug the gamepad, the game correctly detect it !

Problem is, the more time is spent during runtime, the bigger the gap between an "actual gamepad input" and its detection, is... After 2 minutes, it's barely playable ... After 4, the game just doesn't respond to any gamepad input.

Capture2

As said, the "patch" is quite good at its job ! And would be perfect without this problem... Any suggestion ?

Activity

  1. Valkryst commented on Oct 24, 2023

    @Valkryst
    Contributor

    I also wrote a hacky solution for detecting new controllers, using a different method. I'm not sure, but maybe this works without the memory leak that you're running into?

  2. sunsigne commented on Oct 25, 2023

    @sunsigne
    Author

    I also wrote a hacky solution for detecting new controllers, using a different method. I'm not sure, but maybe this works without the memory leak that you're running into?

    Ty ! I'll give a close look, try it, and give feedback soon :)

  3. sunsigne commented on Oct 25, 2023

    @sunsigne
    Author

    I also wrote a hacky solution for detecting new controllers, using a different method. I'm not sure, but maybe this works without the memory leak that you're running into?

    I just tried your "hack", pour over your code to understand what you were doing, slightly adujst it to works with my system, etc.
    You did a pretty job there ! It works perfectly ! It's even easier to use that what i was doing.

    To clarify for people reading this and willing to have a clarification on what our codes are about :
    ControllerEnvironment.getDefaultEnvironment() -> "Env"

    • Mine was "hacking" Env to reset some fields, which cause memory leaks (didn't figure out why, but probably a hidden list filling slowly with more and more new values)
    • his just hacks Env itself to destroy the object, forcing Jinput to rebuild it, which probably destroy the "hidden list causing memory leak"
  4. changed the title [-]Memory leak when updating gamepad detection during Runtime[/-] [+]|Solved] Memory leak when updating gamepad detection during Runtime[/+] on Oct 25, 2023
  5. changed the title [-]|Solved] Memory leak when updating gamepad detection during Runtime[/-] [+][Solved] Memory leak when updating gamepad detection during Runtime[/+] on Oct 25, 2023
  6. Valkryst commented on Oct 25, 2023

    @Valkryst
    Contributor

    @sunsigne

    Someone just found a memory leak in my solution as well. Currently working on a fix

  7. Endolf commented on Oct 25, 2023

    @Endolf
    Collaborator

    Looks like there is some momentum behind this version, good to see.
    The reason for the RawInputEventQueue creating a thread is that direct input (at least on some older version of windows/directx?) required using the same thread to read the data as opened the device, otherwise no data was being read. It could be modified to only create that thread in certain circumstances...
    Linux has a similar issue with the event devices needing a single thread if memory serves.

  8. sunsigne commented on Oct 25, 2023

    @sunsigne
    Author

    @sunsigne

    Someone just found a memory leak in my solution as well. Currently working on a fix

    Ho... well, i didn't noticed it because mine was visible after 5~10 minutes, as yours is 'only' visible after 40 minutes i didn't see it. I'll give a look on the topic and study the problem... I've no doubt we will eventually find a solution :)

  9. changed the title [-][Solved] Memory leak when updating gamepad detection during Runtime[/-] [+][Solved ?] Memory leak when updating gamepad detection during Runtime[/+] on Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions