Repository navigation
Conversation
… pumps events SDL notices a controller plugged in on Windows through a message-only window that its HIDAPI and joystick backends create on the thread that initializes the game controller subsystem, and those messages reach only that thread's queue. VideoOutDriver initialized it with video on the first thread that used video output, while SDL_PollEvent runs on the presentation thread, so a controller unplugged and plugged in again was never seen. PadInput, which the presentation thread creates, now initializes the subsystem when nothing else has, and quits it when it is destroyed on that same thread. VideoOutDriver initializes and quits only video. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested on Fedora Linux (AMD Ryzen 7 9800X3D, RX 7900 XTX), Mesa/RADV. |
BunnyFl
force-pushed
the
fix/videoout-controller-hotplug-thread
branch
from
October 21, 2026 07:50
3b04ff6 to
d318dc9
Compare
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
On Windows, a controller that is unplugged and plugged in again is never seen: the title keeps running without input until it restarts.
SDL learns of device changes on Windows through message-only windows that its HIDAPI backend (
SDL_HIDAPI_DEVICE_DETECTION,src/hidapi/SDL_hidapi.c) and, withoutSDL_HINT_JOYSTICK_THREAD, its Windows joystick backend (src/joystick/windows/SDL_windowsjoystick.c) create on the thread that initializes the game controller subsystem, and Windows delivers theirWM_DEVICECHANGEmessages only to that thread's queue. SDL's own note inSDL_hidapi.c: "We'll only get messages on the same thread that created the window"; it leaves them to the usualSDL_PumpEventsloop.VideoOutDriverinitializedSDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLERon the first thread that used video output (VideoOutDriver::Get), whileSDL_PollEventruns on the presentation thread, soSDL_CONTROLLERDEVICEADDEDnever arrived andPadInput::HandleEventnever reopened the controller.This PR:
VideoOutDriverinitializes and quits onlySDL_INIT_VIDEO.PadInput, which the presentation thread creates before its event loop, already initialized the game controller subsystem when nothing else had; it now does so on that thread and quits it in its destructor, on the same thread (a window can only be destroyed by its own thread). The SDL hints set in theVideoOutDriverconstructor are still set before.PadInputlogsPad: SDL game controller init failedand the title runs with keyboard and mouse input, instead of video output failing to open.Not tested: hot-plug on Linux and macOS, where SDL's device notifications do not go through a window message queue.
Overlap (
tools/pr_overlap.py): #8658 (macOS host) moves the sameSDL_InitSubSystemcall to the main thread on macOS, and #6879 (wasm) edits the line next to theShutdownquit; either merges with this by keeping both changes. Of the pull requests the overlap check could not compare: #7201 (macOS port) also starts the subsystem on the presentation thread, but only whenLibcMainThreadServingis set, so not on Windows; #7881 (four controllers) replacesopenFirstAvailableController, so the second to merge moves the subsystem ownership into its replacement; #674, #5021 and #7499 do not change where the subsystem is initialized.Tested
Windows 11 Pro 10.0.26200, AMD Radeon RX 9070 XT (AMD proprietary driver 26.10.1, LLPC), WinLibs GCC 15.2.0 r7, DualSense over USB,
main86b8424 (the PR is rebased onto 0c50cbf, whose new commits touch none of these files; the 41video_out|padtests pass there too).Ball X Pit (PPSA31872), the DualSense unplugged and plugged in again while the title runs:
Pad: connected game controllerlines in the logmainANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest --test-dir build -R "video_out|pad" -Vonmainand on this PR: 41 of 41 passed on both. 14 skip on both: thevideo_out_flip_*tests andguest_video_out_wqhd_detection_no_vulkan, because theoffscreenSDL driver they run with has no Vulkan on Windows. The validation layer loaded (nowas not found but was requested by env var VK_INSTANCE_LAYERS) and neither log has aVUID-error.As these are the tests that start
VideoOutDriver, I also ranvideo_out_flip_testswithSDL_VIDEODRIVER=windowsand the same three variables forcontrols,cpuflip,decode,eop,eop_aftergpu,eop_main,labels,labels_main,overlay,ps4,reopenandunopened: onmainand on this PR, the same 11 passed andcontrolsfailed withpre-vblank event missingon both; noVUID-error.tools/check_conventions.py --base upstream/mainpasses.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)The investigation, the change and this description were prepared with AI assistance (Claude Code); the controller tests in the title were done by me.
🤖 Generated with Claude Code