Skip to content

Input: Windows: Initialize DirectInput in WorkerThreadPool task#89363

Closed
kavaari wants to merge 1 commit intogodotengine:masterfrom
kavaari:improve-dinput-init
Closed

Input: Windows: Initialize DirectInput in WorkerThreadPool task#89363
kavaari wants to merge 1 commit intogodotengine:masterfrom
kavaari:improve-dinput-init

Conversation

@kavaari
Copy link

@kavaari kavaari commented Mar 10, 2024

This is a proposed improvement to #20566

I have the freeze issue with one of my audio devices causing huge (10s) freeze when USB device is removed / attached or when the game / editor launches, so I was able to debug this and create a workaround.

Fix the initial freeze by initializing DirectInput and enumerating devices in separate thread using the internal worker thread pool.

This doesn't completely solve the issue. Users affected need to wait for the DirectInput devices to be recognized. That can take 10+ seconds, but at least the game / app doesn't freeze. Note that this doesn't affect joypads which support XInput, those work normally and those should work immediately without waiting. Also the freeze can still happen when device is removed and attached immediately. This solution waits for the previous task to complete which then means the main thread is freezed during the wait.

This also improves the DirectInput fallback method. If XInput fails to init for some reason (dll not found), then XInput devices should fallback to DirectInput. That wasn't the case previously.

@kavaari kavaari requested a review from a team as a code owner March 10, 2024 19:01
@AThousandShips AThousandShips added this to the 4.x milestone Mar 10, 2024
@kavaari kavaari changed the title Input: Windows: Initalize DirectInput in WorkerThreadPool task Input: Windows: Initialize DirectInput in WorkerThreadPool task Mar 11, 2024
@AThousandShips
Copy link
Member

You used a merge commit to update your branch, please use rebase in the future instead, see here

@kavaari kavaari force-pushed the improve-dinput-init branch from 7d1aacb to 7acfc50 Compare October 23, 2024 14:07
@kavaari kavaari force-pushed the improve-dinput-init branch from 7acfc50 to 58b96c4 Compare December 1, 2024 20:12
@Calinou
Copy link
Member

Calinou commented Feb 3, 2025

@kavaari Could you look into rebasing this PR on master to fix merge conflicts?

@Calinou Calinou added bug and removed enhancement labels Feb 3, 2025
@Calinou Calinou modified the milestones: 4.x, 4.5 Feb 3, 2025
@Repiteo Repiteo modified the milestones: 4.5, 4.x Sep 18, 2025
@Nintorch
Copy link
Contributor

Hello! We replaced the previous joypad implementation on Windows (and Linux, macOS) with SDL in #106218 , so this PR now changes a file that now doesn't exist. Should this PR be closed or changed to modify SDL's code instead?

@akien-mga
Copy link
Member

This was superseded by #113013.

@akien-mga akien-mga closed this Jan 18, 2026
@akien-mga akien-mga removed this from the 4.x milestone Jan 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants