Skip to content

Commit ff7837e

Browse files
FIX: ISXB-687 Added guard clause to RemovePointerAtIndex in InputSy… (#1982)
* FIX: ISXB-687 Added guard clause to RemovePointerAtIndex in InputSystemUIInputModule to not remove touch pointers on the same frame they are released. * Added changelog entry for fix ISXB-543 * Fixed infinite loop caused by FilterPointerStatesByType() trying to force their release on the same frame they occur. Ran the formatter and applied changes to CHANGELOG.md * Fixed issue where touch pointers don't get released when mouse or pen inputs happen. * Fixed incorrect boolean logic in InputSystemUIInputModule.cs causing certain pointers to be incorrectly released or not released. * Moved changelog entry for ISXB-687 into unreleased. * Moved double touch pointer changelog entry to unreleased. * Removed additional duplicate entries in changelog * Removed superfluous code to get pointer state that is never used in InputSystemUIInputModule.
1 parent 3a96dac commit ff7837e

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ however, it has to be formatted properly to pass verification tests.
1111
## [Unreleased] - yyyy-mm-dd
1212

1313
### Fixed
14+
- Fixed touch pointers being released twice causing an index out of bounds error. [ISXB-687](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-687)
1415
- Fixed `NullReferenceException` from disconnecting and reconnecting a GXDKGamepad.
1516

1617
### Added

Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1947,6 +1947,13 @@ private void RemovePointerAtIndex(int index)
19471947
{
19481948
Debug.Assert(m_PointerStates[index].eventData.pointerEnter == null, "Pointer should have exited all objects before being removed");
19491949

1950+
// We don't want to release touch pointers on the same frame they are released (unpressed). They get cleaned up one frame later in Process()
1951+
ref var state = ref GetPointerStateForIndex(index);
1952+
if (state.pointerType == UIPointerType.Touch && (state.leftButton.isPressed || state.leftButton.wasReleasedThisFrame))
1953+
{
1954+
return;
1955+
}
1956+
19501957
// Retain event data so that we can reuse the event the next time we allocate a PointerModel record.
19511958
var eventData = m_PointerStates[index].eventData;
19521959
Debug.Assert(eventData != null, "Pointer state should have an event instance!");
@@ -2209,7 +2216,13 @@ private void FilterPointerStatesByType()
22092216
// We have input on a mouse or pen. Kill all touch and tracked pointers we may have.
22102217
for (var i = 0; i < m_PointerStates.length; ++i)
22112218
{
2212-
if (m_PointerStates[i].pointerType != UIPointerType.MouseOrPen)
2219+
ref var state = ref GetPointerStateForIndex(i);
2220+
// Touch pointers need to get forced to no longer be pressed otherwise they will not get released in subsequent frames.
2221+
if (m_PointerStates[i].pointerType == UIPointerType.Touch)
2222+
{
2223+
state.leftButton.isPressed = false;
2224+
}
2225+
if (m_PointerStates[i].pointerType != UIPointerType.MouseOrPen && m_PointerStates[i].pointerType != UIPointerType.Touch || (m_PointerStates[i].pointerType == UIPointerType.Touch && !state.leftButton.isPressed && !state.leftButton.wasReleasedThisFrame))
22132226
{
22142227
SendPointerExitEventsAndRemovePointer(i);
22152228
--i;

0 commit comments

Comments
 (0)