Skip to content

fix(runtime): close replaced devices on move assignment - #236

Open
salty-sugar-art wants to merge 1 commit into
LizardByte:masterfrom
salty-sugar-art:fix/runtime-move-cleanup
Open

salty-sugar-art wants to merge 1 commit into
LizardByte:masterfrom
salty-sugar-art:fix/runtime-move-cleanup

Conversation

@salty-sugar-art

Copy link
Copy Markdown

Description

Move-assigning a Runtime discards its old runtime state. Device handles that are still held by the caller keep the old devices alive, and the replacement runtime can no longer close those devices. Move the incoming state through a temporary and swap it into the destination so the temporary closes the replaced devices through the existing destructor. Devices from the incoming runtime stay usable.

Reproduction

  1. Create two runtimes and keep a gamepad handle from each. Use the fake backend for an API-only reproduction, or select the platform backend and Xbox 360 profiles on Linux with writable /dev/uinput. For the Linux check, give the profiles distinct names and record each gamepad's paths from device_nodes().
  2. Move-assign the second runtime into the first with *runtime = std::move(*replacement) while both gamepad handles are alive.
  3. Check is_open() and submit a report through the old handle. On Linux, also check whether the old paths still exist. On 45443d6, the old handle remains open and accepts reports, and the old Linux input device remains registered. With the fix, the old handle reports device_closed, its device node disappears, and the incoming gamepad still accepts input.

Screenshot

Issues Fixed or Closed

Roadmap Issues

Testing

  • Added RuntimeTest.MoveAssignmentClosesReplacedDevices and RuntimeTest.SelfMoveAssignmentKeepsDevicesOpen. Ran --gtest_filter='RuntimeTest.*MoveAssignment*' against the baseline library with the new tests. The cleanup regression failed as expected. Both tests passed with the fix.
  • Built the Linux library and gamepad_adapter with GCC 13.3 on Ubuntu 24.04 under WSL2. Ran a focused GoogleTest binary linked against that library. All 111 selected tests passed, including the runtime and gamepad lifecycle tests.
  • Ran a Linux uinput check with two Xbox 360 devices. Before the fix, both nodes remained after move assignment. With the fix, the old node disappeared and the incoming node stayed online and accepted input. gamepad_adapter x360 also passed.
  • Changed lines passed clang-format --dry-run --Werror and git diff --check.
  • The local build disabled optional XTest and output mapping, and kept an existing unused-parameter warning in the XTest-disabled code as a warning. Windows-driver and macOS tests were outside this run. The Linux UHID smoke test requires /dev/uhid, which was unavailable in this WSL instance.

Type of Change

  • feat: New feature (non-breaking change which adds functionality)
  • fix: Bug fix (non-breaking change which fixes an issue)
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semicolons, etc.)
  • refactor: Code change that neither fixes a bug nor adds a feature
  • perf: Code change that improves performance
  • test: Adding missing tests or correcting existing tests
  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Other changes that don't modify src or test files
  • revert: Reverts a previous commit
  • BREAKING CHANGE: Introduces a breaking change (can be combined with any type above)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas
  • Code docstring/documentation-blocks for new or existing methods/components have been added or updated
  • Tests have been added or updated for new or modified functionality, including regression tests for bug fixes

AI Usage

See our AI usage policy.

  • AI tools were used while preparing this PR

OpenAI Codex (GPT-6, reasoning effort unavailable in this session) investigated the defect, implemented and tested the fix, and prepared this PR description.

@CLAassistant

CLAassistant commented Nov 24, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
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