Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DInputHook: Initialize g_dinput_hook before installing hook. #549

Merged
merged 1 commit into from
Oct 20, 2022

Conversation

gofman
Copy link
Contributor

@gofman gofman commented Oct 20, 2022

Fixes frequent crashes during dinput hooking on Proton (on Windows too but there it is probably a rare occasion).

g_dinput_hook is used in the hook function. DInputHook::DInputHook() sets g_dinput_hook only after hook() finishes. The hook gets active in m_get_device_state_hook->create(), inside MH_EnableHook(). MH_EnableHook() suspends game threads, activates hook and resumes the threads. Once thread calling GetDeviceState() is resumed it may start calling the hook function. The patch fixes the crash which happens frequently under Steam Proton due to that. The crash happens much less often on Windows probably because Proton's ResumeThread() is slower to execute on the calling thread and faster to wake the thread being resumed compared to Windows.

@praydog
Copy link
Owner

praydog commented Oct 20, 2022

Nice catch. It's been a while since I even looked at this particular piece of code, never would've even thought.

@gofman
Copy link
Contributor Author

gofman commented Oct 20, 2022

Nice catch. It's been a while since I even looked at this particular piece of code, never would've even thought.

Oh, its so nice when we can see the source code of what is misbehaving in Proton :)

@praydog praydog merged commit 09dfeac into praydog:master Oct 20, 2022
@gofman gofman deleted the dinput_hook branch October 20, 2022 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants