Skip to content

GameInput: resolve the current token for self-stopping callbacks (OLD-9769) - #1095

Open
sodove wants to merge 2 commits into
ProjectLeonida:mainfrom
sodove:restore/gameinput-current-callback-9769
Open

sodove wants to merge 2 commits into
ProjectLeonida:mainfrom
sodove:restore/gameinput-current-callback-9769

Conversation

@sodove

@sodove sodove commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: OLD-9769 (claim).

What and why

Carry forward @Joaco9020's GameInput fix from draft #46 (old PR 9769). The rebased commit retains the original authorship and has the same stable patch ID as 84dde3f1c. The branch includes current main 75223235d.

A reading callback can pass GAMEINPUT_CURRENT_CALLBACK_TOKEN_VALUE to stop or unregister itself. The shim previously compared that special value directly with the registered tokens, so the callback kept receiving events. The fix resolves it to the callback running on the calling thread and restores the previous token when a nested delivery returns.

Tested

Native Windows 11 build 26100.7623, MSVC 19.44, RelWithDebInfo, pinned SDL 3.4.20, synthetic virtual pad.

  • Control at 3aa975421 with just the new test and ABI constant: 3 of 371 checks failed, covering self-stop and self-unregister.
  • With the fix, all 371 checks passed. The test drives four button changes, and the callback fires once. A stopped callback can still be unregistered by its actual token. A self-unregistered callback is already gone. Three additional CTest runs also passed.
  • Built the production gta6rt executable. In a separate local merge with gameinput: keyboard pad input scripts of any length (RT-INPUT-SCRIPT-LENGTH) #1074 at 5e86f4a3, the default and long-script tests passed (371/371 and 8/8).
  • The translator semantic suite passed (6,168 tests in 470 files). git diff --check and the repository's game-data guard also passed.
  • Main advanced by one unrelated guest-scene test during verification. After integrating it I reran GameInput (371/371) and the updated guest-scene tests (6/6).

GPUs tested: n/a (GameInput and SDL virtual devices).

AI-assisted: yes, OpenAI Codex for the rebase and Windows verification. The original commit retains its co-author credit.

Checklist

  • Includes current main and merges cleanly.
  • One topic.
  • No game data, keys or decryption.
  • Translator-contract checklist item is inapplicable to this GameInput change.

Joaco9020 and others added 2 commits November 24, 2026 23:16
…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>

@abnalstlll-byte abnalstlll-byte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Audited and verified. Implements GAMEINPUT_CURRENT_CALLBACK_TOKEN_VALUE resolution via RAII-scoped hread_local t_running_token in
untime/shims/gameinput.cpp, allowing self-stopping and self-unregistering callbacks during execution while safely ignoring calls from outside callbacks. Comprehensive unit tests in
untime/test/gameinput_test.cpp pass cleanly. Approved.

@abnalstlll-byte abnalstlll-byte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean-Room Audit — PR #1095 (OLD-9769 GameInput Current-Callback Token)

Clean resolution of GAMEINPUT_CURRENT_CALLBACK_TOKEN_VALUE (0xFFFFFFFFFFFFFFFFull) in runtime/shims/gameinput.cpp via thread-local running token RAII guard, allowing StopCallback and UnregisterCallback inside active callbacks without deadlock. Covered in runtime/test/gameinput_test.cpp; 0 game data.

Verdict: APPROVED

@Deedlyy

Deedlyy commented Nov 24, 2026

Copy link
Copy Markdown

Recommendation: [MERGE]

Reasoning: Carries #46's GameInput fix: GAMEINPUT_CURRENT_CALLBACK_TOKEN_VALUE now resolves to the running callback, so a self-stopping/unregistering callback actually stops. Small, focused shim change with a new regression test in gameinput_test.cpp. No second-person run yet, but the change is narrow and low risk. CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict with main. Merge once the queued checks are green.

Impact level: 4/10

@whoalin1

Copy link
Copy Markdown
Contributor

Independent verification at head a3158989c (Windows 11, MSVC 19.44, RelWithDebInfo, pinned SDL3 3.4.20 fetched via LEONIDA_SDL3_FETCH=ON):

  • Built gameinput_test and ran it: 371 checks, 0 failures, including all seven new current token checks (self-UnregisterCallback and self-StopCallback via GAMEINPUT_CURRENT_CALLBACK_TOKEN_VALUE, plus the outside-a-callback negative cases).
  • Diff review: kCurrentCallbackToken = 0xFFFFFFFFFFFFFFFF matches GAMEINPUT_CURRENT_CALLBACK_TOKEN_VALUE; the thread_local running token is set/restore-scoped inside call(), so nested deliveries keep their own token; only StopCallback/UnregisterCallback accept a token, and both now resolve before lookup. Invalid-token early returns look right.
  • No real GameInput hardware needed — the test drives SDL virtual joysticks through the shim, so this fully verifies on a controller-less machine.

The only PR check is the label workflow, which shows cancelled (superseded), not a code failure.

Verdict: verified, looks correct. — AI-assisted verification (Devin)

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.

5 participants