Repository navigation
Cocoa Port: Fix HID controller crashes and spurious input - #992
Open
dev-jpoliveira wants to merge 1 commit into
Open
dev-jpoliveira wants to merge 1 commit into
dev-jpoliveira wants to merge 1 commit into
Conversation
Validate optional numeric device properties before reading them, and reject unusable elements before normalizing their values. Reserve hat and axis output capacity instead of inserting empty input records. Ignore the Switch Pro Controller proprietary 0x30 report in the generic HID parser; decoded input remains available through macOS controller compatibility. Preserve standard reports and other device IDs. Add a standalone Cocoa parser regression check covering 15 cases.
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.
Problem and reproduction
On macOS 26.6.2 / Apple Silicon, mapping a Nintendo Switch Pro Controller (VID
057e, PID2009) in the Cocoa frontend exposed two paths:0x0000/0xFFFFFFFF (nan)and rapidly changing button inputs while the controller was idle. Selecting a command could bind an input without a physical press.CFNumberGetValue. The macOS synthetic controller does not necessarily provide aLocationID, but the device-code helper read it unconditionally.These symptoms were reproduced with 0.9.13. The affected parser code is still present in
master(base1275dc6). A ROM is not needed: connect the controller, open Settings → Input, select Up, then press and release the D-pad direction.Proposed fix
CFNumber; fall back to zero for missing or incorrectly typed numeric properties.NaN.resize()followed bypush_back()withreserve()when expanding hats and digital axis thresholds. The old code returned extra empty entries (eight instead of four for a hat; four instead of two for an axis).0x30report in the generic HID element parser. Its payload starts with a counter and battery/connection data before the buttons; interpreting it through the generic descriptor produces spurious presses. The filter is restricted to this VID/PID and report ID. Standard0x3freports and other devices remain eligible for parsing.The Switch path uses the decoded synthetic controller supplied by macOS compatibility (
GamePad-1). This change does not implement a Nintendo protocol decoder and does not automatically enable compatibility. It always discards the specified proprietary report, whether or not a synthetic device is currently available.Protocol reference: SDL Switch report IDs and packet layouts.
Validation
python3 desmume/src/frontend/cocoa/tests/test_hid_input.py.masterplus this patch successfully with Xcode 26.4.1, the Apple Silicon Latest scheme, Release configuration and macOS 11.0 deployment target.GamePad-1, mapped without a crash and remained mapped after a full app restart. No ROM or save was used in this validation. The user subsequently reported successful operation following a Bluetooth setup test; that Bluetooth result was not independently instrumented.The master-based build has not been physically tested. Other controller models, multiple synthetic controllers and older macOS versions have not been physically tested. Production code avoids Objective-C numeric literals to preserve compatibility with the legacy compiler targets.