Skip to content

gameinput: StopCallback and UnregisterCallback take the current-callback token - #46

Closed
Andretuta wants to merge 1 commit into
mainfrom
old-pr/9769
Closed

Andretuta wants to merge 1 commit into
mainfrom
old-pr/9769

Conversation

@Andretuta

Copy link
Copy Markdown
Collaborator

Carried over from old PR 9769 by Joaco9020 in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/9769, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
Joaco9020: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

Claim: https://github.com/ProjectLeonida/Leonida/issues/9677#issuecomment-7115375665 (from @Maraco91's finding: https://github.com/ProjectLeonida/Leonida/issues/9677#issuecomment-7115359105)

Depends on: none. Overlaps: #9264 and #5109 also edit UnregisterCallback / the delivery path in runtime/shims/gameinput.cpp; this change adds two lines at the top of StopCallback and UnregisterCallback and a guard in call(), so whichever lands second needs a small rebase.

What and why

GAMEINPUT_CURRENT_CALLBACK_TOKEN_VALUE (0xFFFFFFFFFFFFFFFF) names the callback that is running on the calling thread. The host's GameInput (0.2309, Windows 11, measured in the finding) treats it that way: inside a callback UnregisterCallback(CURRENT, 0) removes that callback and returns true, and StopCallback(CURRENT) stops it; outside a callback the token names nothing and UnregisterCallback returns false. The shim compared the constant with the registered tokens, matched none, and the callback kept firing, also after a title had freed its context.

  • gameinput_abi.h: kCurrentCallbackToken.
  • gameinput.cpp: call() records the running callback's token in a thread_local, restored on return (so a callback that drives another delivery keeps its own); StopCallback and UnregisterCallback resolve the constant through it, and with no running callback do nothing / return false.
  • gameinput_test.cpp: a reading callback on the virtual Xbox pad that cancels itself with the constant on its first call must run once for four button changes, once with UnregisterCallback (which must return true, after which the real token is gone) and once with StopCallback (the callback stays registered); the constant outside a callback returns false.

Tested

Windows 11, MSVC 19.44 (VS 2022 Build Tools), SDL3 fetched with -DLEONIDA_SDL3_FETCH=ON, on main 5d74c2723:

  • gameinput_test: 348 checks, 0 failures (7 new).
  • Negative control: the new test against the old gameinput.cpp (only the header constant added): 348 checks, 3 failures, exactly the three new behaviour checks.
  • gameinput_probe and gta6rt build with the change.

No game files, no controller (SDL virtual pads only). Whether the retail title passes the constant is not measured.

AI-assisted: yes (Claude).

🤖 Generated with Claude Code

…ack token

GAMEINPUT_CURRENT_CALLBACK_TOKEN_VALUE (all ones) names the callback that is
running on the calling thread, as the host's GameInput does (measured by
@Maraco91 on GameInput 0.2309): inside a callback, UnregisterCallback(CURRENT)
removes it and returns true and StopCallback(CURRENT) stops it; outside one the
token names nothing and UnregisterCallback returns false. The shim compared
it with registered tokens, matched none, and the callback kept firing.

call() records the running token in a thread_local, restored on return, and
both methods resolve the constant through it. gameinput_test drives a
self-cancelling reading callback through four button changes on the virtual
Xbox pad, once per method.

Finding: https://github.com/ProjectLeonida/Leonida/issues/9677#issuecomment-7115359105

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aslan2142

Copy link
Copy Markdown
Collaborator

This carry-over of old upstream PR 9769 has been taken over in #1095, so I'm closing this draft as #17 describes. The branch old-pr/9769 stays.

AI-assisted (Claude Code, Claude Opus 5.5).

@aslan2142 aslan2142 closed this Nov 24, 2026
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.

3 participants