-
Notifications
You must be signed in to change notification settings - Fork 338
FIX: Add test and fix for multiple touchscreen input bug. #2434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Darren-Kelly-Unity
wants to merge
2
commits into
develop
Choose a base branch
from
bugfix/UUM-112247-multiple-touchscreens-incorrect-input
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+95
−3
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| using NUnit.Framework; | ||
| using UnityEngine; | ||
| using UnityEngine.InputSystem; | ||
| using UnityEngine.InputSystem.LowLevel; | ||
| using TouchPhase = UnityEngine.InputSystem.TouchPhase; | ||
|
|
||
| // Tests covering touch tracking across multiple physical touchscreen monitors. | ||
| // Regression coverage for IN-108611: touches from one screen incorrectly matching | ||
| // ongoing touches from another screen when both screens report the same touchId. | ||
| [TestFixture] | ||
| internal class TouchscreenMultiDisplayTests : CoreTestsFixture | ||
| { | ||
| // When two physical touchscreens both have an active touch with the same touchId, | ||
| // a Move event from screen 2 must update screen 2's touch slot, not screen 1's. | ||
| // | ||
| // Failure mode (pre-fix): OnStateEvent matches ongoing touches by touchId alone, | ||
| // so screen 2's Move event finds screen 1's slot first (both have touchId=1) and | ||
| // incorrectly updates it, leaving screen 1's position changed and screen 2 stale. | ||
| [Test] | ||
| [Category("Devices")] | ||
| public void Devices_TouchMoveOnSecondDisplay_DoesNotUpdateTouchOnFirstDisplay() | ||
| { | ||
| var device = InputSystem.AddDevice<Touchscreen>(); | ||
|
|
||
| // Finger down on display 0 (touchId=1). | ||
| InputSystem.QueueStateEvent(device, new TouchState | ||
| { | ||
| phase = TouchPhase.Began, | ||
| touchId = 1, | ||
| position = new Vector2(100, 100), | ||
| displayIndex = 0, | ||
| }); | ||
|
|
||
| // Finger down on display 1 — same touchId, different screen. | ||
| InputSystem.QueueStateEvent(device, new TouchState | ||
| { | ||
| phase = TouchPhase.Began, | ||
| touchId = 1, | ||
| position = new Vector2(200, 200), | ||
| displayIndex = 1, | ||
| }); | ||
|
|
||
| InputSystem.Update(); | ||
|
|
||
| // Both touches should be allocated to separate slots. | ||
| Assert.That(device.touches[0].phase.ReadValue(), Is.EqualTo(TouchPhase.Began)); | ||
| Assert.That(device.touches[1].phase.ReadValue(), Is.EqualTo(TouchPhase.Began)); | ||
|
|
||
| var display0SlotIndex = -1; | ||
| var display1SlotIndex = -1; | ||
| for (var i = 0; i < 2; i++) | ||
| { | ||
| var displayIdx = device.touches[i].displayIndex.ReadValue(); | ||
| if (displayIdx == 0) display0SlotIndex = i; | ||
| else if (displayIdx == 1) display1SlotIndex = i; | ||
| } | ||
|
|
||
| Assert.That(display0SlotIndex, Is.Not.EqualTo(-1), "No touch slot found for display 0"); | ||
| Assert.That(display1SlotIndex, Is.Not.EqualTo(-1), "No touch slot found for display 1"); | ||
|
|
||
| var display0PositionBefore = device.touches[display0SlotIndex].position.ReadValue(); | ||
|
|
||
| // Swipe on display 1 (same touchId=1 as display 0's held touch). | ||
| InputSystem.QueueStateEvent(device, new TouchState | ||
| { | ||
| phase = TouchPhase.Moved, | ||
| touchId = 1, | ||
| position = new Vector2(300, 300), | ||
| displayIndex = 1, | ||
| }); | ||
|
|
||
| InputSystem.Update(); | ||
|
|
||
| // Display 0's touch must be unchanged. | ||
| Assert.That(device.touches[display0SlotIndex].position.ReadValue(), Is.EqualTo(display0PositionBefore), | ||
| "Touch on display 0 was incorrectly updated by a Move event from display 1"); | ||
|
|
||
| // Display 1's touch must reflect the new position. | ||
| Assert.That(device.touches[display1SlotIndex].position.ReadValue(), Is.EqualTo(new Vector2(300, 300)), | ||
| "Touch on display 1 was not updated by its own Move event"); | ||
|
|
||
| Assert.That(device.touches[display1SlotIndex].phase.ReadValue(), Is.EqualTo(TouchPhase.Moved)); | ||
| } | ||
| } |
2 changes: 2 additions & 0 deletions
2
Assets/Tests/InputSystem/TouchscreenMultiDisplayTests.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.