Skip to content

Conversation

ekcoh
Copy link
Collaborator

@ekcoh ekcoh commented Oct 7, 2025

Description

This PR addresses user reported issue: https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1637 in the following ways:

  • Adds a direct null pointer check to DeltaStateEvent.cs where pointer arithmetic would be incorrect and lead to exception or crash when offsetting a nullptr.
  • Adds an indirect null pointer check to InputTestFixture.cs (via new internal property InputControl.hasState) where accessing a device from "outside" test context would lead to the same symptoms as above. This is now instead checked and throws exception if this is attempted.
  • Adds detection and throws exception if detecting InputTestFixture Set operations being used in an editor-assembly with [UnityTest] tests. Documented this and previously undocumented exceptions in xmldoc.
  • Adds new test class InputTestFixtureTests that verifies normal behavior in InputTestFixture as well as inappropriate use similar to the reported repro project and verifies that expected exceptions are thrown for these scenarios.

The problem in the provided repro project is two-fold:

  • Using [OneTimeSetup] and [OneTimeTearDown] to manage test devices. This will not work as intended since the device will be added to the real Input System context, then removed as part of InputTestFixture.Setup(). To reduce chance of similar accidental situations, I have added information recommending against this to InputTestFixture xmldoc. In addition, if this is attempted it should result in exception which is verified in the added tests.
  • Using InputTestFixture in edit-mode tests [UnityTest] which isn't fully supported it seems.

Notice that I decided to block use of InputTestFixture and its Set-family of operations in editor-assembly tests. The reason for this is that InputManager will not process such updates, it will switch to editor buffers and then early out. I do not see any scenario where this may cause problems but if you do let me know and we update accordingly. The changes on this PR is intended to detect and inform about unintended or unsupported use of a test fixture.

Testing status & QA

Added multiple automated edit-mode tests into InputTestFixtureTests

Overall Product Risks

  • Complexity: Small
  • Halo Effect: Small

Comments to reviewers

Good to check that you are aligned on this clarification and blocking certain behavior.

Checklist

Before review:

  • Changelog entry added.
    • Explains the change in Changed, Fixed, Added sections.
    • For API change contains an example snippet and/or migration example.
    • JIRA ticket linked, example (case %%). If it is a private issue, just add the case ID without a link.
    • Jira port for the next release set as "Resolved".
  • Tests added/changed, if applicable.
    • Functional tests: Multiple tests added in InputTestFixtureTests
    • Performance tests.
    • Integration tests.
  • Docs for new/changed API's.
    • Xmldoc cross references are set correctly.
    • Added explanation how the API works.
    • Usage code examples added.
    • The manual is updated, if needed.

During merge:

  • Commit message for squash-merge is prefixed with one of the list:
    • NEW: ___.
    • FIX: ___.
    • DOCS: ___.
    • CHANGE: ___.
    • RELEASE: 1.1.0-preview.3.

After merge:

  • Create forward/backward port if needed. If you are blocked from creating a forward port now please add a task to ISX-1444.
@ekcoh ekcoh marked this pull request as ready for review October 8, 2025 08:39
@ekcoh ekcoh requested review from K-Tone and Pauliusd01 October 8, 2025 08:41
@codecov-github-com
Copy link

codecov-github-com bot commented Oct 8, 2025

Codecov Report

Attention: Patch coverage is 97.77778% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
....inputsystem/Tests/TestFixture/InputTestFixture.cs 90.47% 2 Missing ⚠️
....inputsystem/InputSystem/Events/DeltaStateEvent.cs 50.00% 1 Missing ⚠️
@@ Coverage Diff @@ ## develop #2254 +/- ## =========================================== - Coverage 76.70% 76.68% -0.03%  =========================================== Files 465 468 +3 Lines 87919 88172 +253 =========================================== + Hits 67442 67614 +172  - Misses 20477 20558 +81 
Flag Coverage Δ
inputsystem_MacOS_2021.3 5.90% <0.00%> (-0.01%) ⬇️
inputsystem_MacOS_2022.3 5.37% <0.00%> (-0.01%) ⬇️
inputsystem_MacOS_2022.3_project 74.57% <97.77%> (-0.02%) ⬇️
inputsystem_MacOS_6000.0 5.18% <0.00%> (-0.01%) ⬇️
inputsystem_MacOS_6000.0_project 76.49% <97.77%> (-0.02%) ⬇️
inputsystem_MacOS_6000.2 5.18% <0.00%> (-0.01%) ⬇️
inputsystem_MacOS_6000.2_project 76.48% <97.77%> (-0.02%) ⬇️
inputsystem_MacOS_6000.3 5.18% <0.00%> (-0.01%) ⬇️
inputsystem_MacOS_6000.3_project 76.48% <97.77%> (-0.02%) ⬇️
inputsystem_MacOS_6000.4 5.18% <0.00%> (-0.01%) ⬇️
inputsystem_MacOS_6000.4_project 76.48% <97.77%> (-0.02%) ⬇️
inputsystem_Ubuntu_2021.3 5.91% <0.00%> (-0.01%) ⬇️
inputsystem_Ubuntu_2022.3 5.37% <0.00%> (-0.01%) ⬇️
inputsystem_Ubuntu_2022.3_project 74.38% <97.77%> (-0.02%) ⬇️
inputsystem_Ubuntu_6000.0 5.19% <0.00%> (-0.01%) ⬇️
inputsystem_Ubuntu_6000.0_project 76.30% <97.77%> (-0.02%) ⬇️
inputsystem_Ubuntu_6000.2 5.19% <0.00%> (-0.01%) ⬇️
inputsystem_Ubuntu_6000.2_project 76.30% <97.77%> (-0.02%) ⬇️
inputsystem_Ubuntu_6000.3 5.19% <0.00%> (-0.01%) ⬇️
inputsystem_Ubuntu_6000.3_project 76.30% <97.77%> (-0.02%) ⬇️
inputsystem_Ubuntu_6000.4 5.19% <0.00%> (-0.01%) ⬇️
inputsystem_Ubuntu_6000.4_project 76.30% <97.77%> (-0.03%) ⬇️
inputsystem_Windows_2021.3 5.90% <0.00%> (-0.01%) ⬇️
inputsystem_Windows_2022.3 5.37% <0.00%> (-0.01%) ⬇️
inputsystem_Windows_2022.3_project 74.71% <97.77%> (-0.02%) ⬇️
inputsystem_Windows_6000.0 5.18% <0.00%> (-0.01%) ⬇️
inputsystem_Windows_6000.0_project 76.63% <97.77%> (-0.02%) ⬇️
inputsystem_Windows_6000.2 5.18% <0.00%> (-0.01%) ⬇️
inputsystem_Windows_6000.2_project 76.62% <97.77%> (-0.02%) ⬇️
inputsystem_Windows_6000.3 5.18% <0.00%> (-0.01%) ⬇️
inputsystem_Windows_6000.3_project 76.62% <97.77%> (-0.02%) ⬇️
inputsystem_Windows_6000.4 5.18% <0.00%> (-0.01%) ⬇️
inputsystem_Windows_6000.4_project 76.62% <97.77%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
.../Tests/InputSystem.Editor/InputTestFixtureTests.cs 100.00% <100.00%> (ø)
.../com.unity.inputsystem/InputSystem/InputManager.cs 88.79% <100.00%> (+0.01%) ⬆️
....inputsystem/InputSystem/Events/DeltaStateEvent.cs 79.59% <50.00%> (-1.26%) ⬇️
....inputsystem/Tests/TestFixture/InputTestFixture.cs 78.78% <90.47%> (+0.66%) ⬆️

... and 7 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
Copy link
Collaborator

@K-Tone K-Tone left a comment

Choose a reason for hiding this comment

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

I'd ask to remove TODO and adjust spelling in a few spots, otherwise looks pretty good

ekcoh and others added 6 commits October 8, 2025 11:21
…ent.cs Co-authored-by: Anthony Yakovlev <anthony.yakovlev@gmail.com>
…ure.cs Co-authored-by: Anthony Yakovlev <anthony.yakovlev@gmail.com>
…ure.cs Co-authored-by: Anthony Yakovlev <anthony.yakovlev@gmail.com>
Co-authored-by: Anthony Yakovlev <anthony.yakovlev@gmail.com>
…sing check for SetTouch. Minor refactoring to reduce code bloat.
…gies/InputSystem into isxb-1637-crash-on-memcpy
@ekcoh
Copy link
Collaborator Author

ekcoh commented Oct 8, 2025

@K-Tone Thanks for the feedback. It was very valuable since I realised I had missed the same problem with touch APIs. It's not addressed and have been committed with additional tests to cover touch APIs as well as Vector2 API.

@ekcoh ekcoh requested a review from K-Tone October 8, 2025 10:47
Copy link
Collaborator

@K-Tone K-Tone left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks for addressing the comments!

@ekcoh
Copy link
Collaborator Author

ekcoh commented Oct 8, 2025

Interesting that CI behaves differently on Windows than on other platforms, some new editor tests failing. Will need to investigate on Windows I guess.

@ekcoh
Copy link
Collaborator Author

ekcoh commented Oct 8, 2025

I am not understanding these failures. They are all green when I execute them locally on Windows 10.

@ekcoh
Copy link
Collaborator Author

ekcoh commented Oct 10, 2025

I updated the approach taken here to a more direct approach after I realised push/pop in Input manager isn't consistently pushing/popping devices and also to not manage dangling references in such devices. This is likely another area that needs attention (test scope only).

@ekcoh ekcoh requested review from K-Tone and Pauliusd01 October 10, 2025 13:24
@ekcoh
Copy link
Collaborator Author

ekcoh commented Oct 10, 2025

Re-requesting review on this one since the previous approach had flaws. Se commits from ef7b23d and forward.

@ekcoh ekcoh merged commit 49234f5 into develop Oct 13, 2025
115 checks passed
@ekcoh ekcoh deleted the isxb-1637-crash-on-memcpy branch October 13, 2025 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants