From d280dff67f9233647376b3df3e9020f34e6b5ce8 Mon Sep 17 00:00:00 2001 From: Adrian Koretski Date: Mon, 12 Aug 2024 10:41:14 -0400 Subject: [PATCH 1/9] FIX: ISXB-687 Added guard clause to RemovePointerAtIndex in InputSystemUIInputModule to not remove touch pointers on the same frame they are released. --- .../InputSystem/Plugins/UI/InputSystemUIInputModule.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs index 9f38d97ad5..8ec584fdba 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs @@ -1897,6 +1897,13 @@ private void RemovePointerAtIndex(int index) { Debug.Assert(m_PointerStates[index].eventData.pointerEnter == null, "Pointer should have exited all objects before being removed"); + // We don't want to release touch pointers on the same frame they are released. They get cleaned up one frame later in Process() + ref var state = ref GetPointerStateForIndex(index); + if (state.pointerType == UIPointerType.Touch && (state.leftButton.isPressed || state.leftButton.wasReleasedThisFrame)) + { + return; + } + // Retain event data so that we can reuse the event the next time we allocate a PointerModel record. var eventData = m_PointerStates[index].eventData; Debug.Assert(eventData != null, "Pointer state should have an event instance!"); From 8d3ca934d69512154fda7003511c94121b99706d Mon Sep 17 00:00:00 2001 From: Adrian Koretski Date: Mon, 12 Aug 2024 11:09:55 -0400 Subject: [PATCH 2/9] Added changelog entry for fix ISXB-543 --- Packages/com.unity.inputsystem/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index e862623141..ef2b43ac9b 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -13,6 +13,7 @@ however, it has to be formatted properly to pass verification tests. ### Fixed - Fixed memory allocation on every frame when using UIDocument without EventSystem. [ISXB-953](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-953) - Fixed Action Maps name edition which could be inconsistent in Input Action Editor UI. +- Fixed touch pointers being released twice causing an index out of bounds error. ### Changed - Use `ProfilerMarker` instead of `Profiler.BeginSample` and `Profiler.EndSample` when appropriate to enable recording of profiling data. From 1f4e41c61bf5ec01e6b65cb67b071c18c5218181 Mon Sep 17 00:00:00 2001 From: Adrian Koretski Date: Thu, 12 Sep 2024 16:20:32 -0400 Subject: [PATCH 3/9] 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 --- Packages/com.unity.inputsystem/CHANGELOG.md | 2 +- .../InputSystem/Plugins/UI/InputSystemUIInputModule.cs | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index f6ebeac4d2..c2084cba26 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -13,7 +13,7 @@ however, it has to be formatted properly to pass verification tests. ### Fixed - Fixed memory allocation on every frame when using UIDocument without EventSystem. [ISXB-953](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-953) - Fixed Action Maps name edition which could be inconsistent in Input Action Editor UI. -- Fixed touch pointers being released twice causing an index out of bounds error. +- Fixed touch pointers being released twice causing an index out of bounds error. ### Added - Added Hinge Angle sensor support for foldable devices. diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs index 0d52c13d94..7b101e6453 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs @@ -1947,7 +1947,7 @@ private void RemovePointerAtIndex(int index) { Debug.Assert(m_PointerStates[index].eventData.pointerEnter == null, "Pointer should have exited all objects before being removed"); - // We don't want to release touch pointers on the same frame they are released. They get cleaned up one frame later in Process() + // 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() ref var state = ref GetPointerStateForIndex(index); if (state.pointerType == UIPointerType.Touch && (state.leftButton.isPressed || state.leftButton.wasReleasedThisFrame)) { @@ -2216,7 +2216,8 @@ private void FilterPointerStatesByType() // We have input on a mouse or pen. Kill all touch and tracked pointers we may have. for (var i = 0; i < m_PointerStates.length; ++i) { - if (m_PointerStates[i].pointerType != UIPointerType.MouseOrPen) + ref var state = ref GetPointerStateForIndex(i); + if (m_PointerStates[i].pointerType != UIPointerType.MouseOrPen && !state.leftButton.isPressed && !state.leftButton.wasReleasedThisFrame) { SendPointerExitEventsAndRemovePointer(i); --i; @@ -2228,7 +2229,8 @@ private void FilterPointerStatesByType() // We have touch or tracked input. Kill mouse/pen pointer, if we have it. for (var i = 0; i < m_PointerStates.length; ++i) { - if (m_PointerStates[i].pointerType == UIPointerType.MouseOrPen) + ref var state = ref GetPointerStateForIndex(i); + if (m_PointerStates[i].pointerType == UIPointerType.MouseOrPen && !state.leftButton.isPressed && !state.leftButton.wasReleasedThisFrame) { SendPointerExitEventsAndRemovePointer(i); --i; From 84e2ca4087d6b8ebaabf69188880f51cf3d96f32 Mon Sep 17 00:00:00 2001 From: Adrian Koretski Date: Mon, 16 Sep 2024 16:49:28 -0400 Subject: [PATCH 4/9] Fixed issue where touch pointers don't get released when mouse or pen inputs happen. --- .../Plugins/UI/InputSystemUIInputModule.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs index 7b101e6453..0f686613ca 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs @@ -2217,7 +2217,12 @@ private void FilterPointerStatesByType() for (var i = 0; i < m_PointerStates.length; ++i) { ref var state = ref GetPointerStateForIndex(i); - if (m_PointerStates[i].pointerType != UIPointerType.MouseOrPen && !state.leftButton.isPressed && !state.leftButton.wasReleasedThisFrame) + // Touch pointers need to get forced to no longer be pressed otherwise they will not get released in subsequent frames. + if (m_PointerStates[i].pointerType == UIPointerType.Touch) + { + state.leftButton.isPressed = false; + } + if (m_PointerStates[i].pointerType != UIPointerType.MouseOrPen || (m_PointerStates[i].pointerType == UIPointerType.Touch && !state.leftButton.isPressed && !state.leftButton.wasReleasedThisFrame)) { SendPointerExitEventsAndRemovePointer(i); --i; @@ -2230,7 +2235,12 @@ private void FilterPointerStatesByType() for (var i = 0; i < m_PointerStates.length; ++i) { ref var state = ref GetPointerStateForIndex(i); - if (m_PointerStates[i].pointerType == UIPointerType.MouseOrPen && !state.leftButton.isPressed && !state.leftButton.wasReleasedThisFrame) + // Touch pointers need to get forced to no longer be pressed otherwise they will not get released in subsequent frames. + if (m_PointerStates[i].pointerType == UIPointerType.Touch) + { + state.leftButton.isPressed = false; + } + if (m_PointerStates[i].pointerType == UIPointerType.MouseOrPen || (m_PointerStates[i].pointerType == UIPointerType.Touch && !state.leftButton.isPressed && !state.leftButton.wasReleasedThisFrame)) { SendPointerExitEventsAndRemovePointer(i); --i; From 22183dfe988c9b43da30ad0e9127196ff8c2f7df Mon Sep 17 00:00:00 2001 From: Adrian Koretski Date: Tue, 17 Sep 2024 13:54:34 -0400 Subject: [PATCH 5/9] Fixed incorrect boolean logic in InputSystemUIInputModule.cs causing certain pointers to be incorrectly released or not released. --- .../Plugins/UI/InputSystemUIInputModule.cs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs index 0f686613ca..c26f086163 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs @@ -2217,12 +2217,12 @@ private void FilterPointerStatesByType() for (var i = 0; i < m_PointerStates.length; ++i) { ref var state = ref GetPointerStateForIndex(i); - // Touch pointers need to get forced to no longer be pressed otherwise they will not get released in subsequent frames. + // Touch pointers need to get forced to no longer be pressed otherwise they will not get released in subsequent frames. if (m_PointerStates[i].pointerType == UIPointerType.Touch) { state.leftButton.isPressed = false; } - if (m_PointerStates[i].pointerType != UIPointerType.MouseOrPen || (m_PointerStates[i].pointerType == UIPointerType.Touch && !state.leftButton.isPressed && !state.leftButton.wasReleasedThisFrame)) + 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)) { SendPointerExitEventsAndRemovePointer(i); --i; @@ -2235,12 +2235,8 @@ private void FilterPointerStatesByType() for (var i = 0; i < m_PointerStates.length; ++i) { ref var state = ref GetPointerStateForIndex(i); - // Touch pointers need to get forced to no longer be pressed otherwise they will not get released in subsequent frames. - if (m_PointerStates[i].pointerType == UIPointerType.Touch) - { - state.leftButton.isPressed = false; - } - if (m_PointerStates[i].pointerType == UIPointerType.MouseOrPen || (m_PointerStates[i].pointerType == UIPointerType.Touch && !state.leftButton.isPressed && !state.leftButton.wasReleasedThisFrame)) + // Touch pointers need to get forced to no longer be pressed otherwise they will not get released in subsequent frames. + if (m_PointerStates[i].pointerType == UIPointerType.MouseOrPen) { SendPointerExitEventsAndRemovePointer(i); --i; From 11b8a0eeccb008dd3ea4acae5283bbe5044cc367 Mon Sep 17 00:00:00 2001 From: Adrian Koretski Date: Thu, 19 Sep 2024 16:17:34 -0400 Subject: [PATCH 6/9] Moved changelog entry for ISXB-687 into unreleased. --- Packages/com.unity.inputsystem/CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index de0aac189b..9e81d85ba2 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -10,6 +10,9 @@ however, it has to be formatted properly to pass verification tests. ## [Unreleased] - yyyy-mm-dd +### Fixed +- 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) + ### Changed - Renamed editor Resources directories to PackageResources to fix package validation warnings. @@ -18,7 +21,6 @@ however, it has to be formatted properly to pass verification tests. ### Fixed - Fixed memory allocation on every frame when using UIDocument without EventSystem. [ISXB-953](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-953) - Fixed Action Maps name edition which could be inconsistent in Input Action Editor UI. -- Fixed touch pointers being released twice causing an index out of bounds error. ### Added - Added Hinge Angle sensor support for foldable devices. From efe6c3c279402511736fa4a10920a1c2c636224d Mon Sep 17 00:00:00 2001 From: Adrian Koretski Date: Fri, 27 Sep 2024 09:21:15 -0400 Subject: [PATCH 7/9] Moved double touch pointer changelog entry to unreleased. --- Packages/com.unity.inputsystem/CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index 4b3624ff4b..5c7e50448d 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -10,13 +10,15 @@ however, it has to be formatted properly to pass verification tests. ## [Unreleased] - yyyy-mm-dd +### Fixed +- 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) + ### Added - Added the display of the device flag `CanRunInBackground` in device debug view. ## [1.11.1] - 2024-09-26 ### Fixed -- 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) - Fixed Multiple interactions could breaks on Composite Binding. [ISXB-619](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-619) - Fixed memory leak when the OnScreenStick component was destroyed [ISXB-1070](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1070). Contribution by [LukeUnityDev](https://github.com/LukeUnityDev). - Fixed Action Maps contextual menu in Action Editor UI that occasionally displays unrelated items. From cd89b85897bd5354945067869f62171c4d1982e9 Mon Sep 17 00:00:00 2001 From: Adrian Koretski Date: Fri, 27 Sep 2024 09:58:54 -0400 Subject: [PATCH 8/9] Removed additional duplicate entries in changelog --- Packages/com.unity.inputsystem/CHANGELOG.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index 5c7e50448d..e6a330f550 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -36,9 +36,6 @@ however, it has to be formatted properly to pass verification tests. ### Fixed - Fixed memory allocation on every frame when using UIDocument without EventSystem. [ISXB-953](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-953) - Fixed Action Maps name edition which could be inconsistent in Input Action Editor UI. - -### Added -- Added Hinge Angle sensor support for foldable devices. - Fixed InputDeviceTester sample only visualizing a given touch contact once. [ISXB-1017](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1017) - Fixed an update loop in the asset editor that occurs when selecting an Action Map that has no Actions. - Fixed Package compilation when Unity Analytics module is not enabled on 2022.3. [ISXB-996](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-996) @@ -56,7 +53,6 @@ however, it has to be formatted properly to pass verification tests. - Added tests for Input Action Editor UI for managing action maps (List, create, rename, delete) (ISX-2087) - Added automatic loading of custom extensions of InputProcessor, InputInteraction and InputBindingComposite [ISXB-856]](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-856). - Added an IME Input sample scene. -- Added analytics for programmatic `InputAction` setup via `InputActionSetupExtensions`. ## [1.10.0] - 2024-07-24 From 969970331abaf57beaf9e4c9dcc12499390834f4 Mon Sep 17 00:00:00 2001 From: Adrian Koretski Date: Fri, 27 Sep 2024 10:39:05 -0400 Subject: [PATCH 9/9] Removed superfluous code to get pointer state that is never used in InputSystemUIInputModule. --- .../InputSystem/Plugins/UI/InputSystemUIInputModule.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs index 74224af95a..c65c6a6700 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs @@ -2234,8 +2234,6 @@ private void FilterPointerStatesByType() // We have touch or tracked input. Kill mouse/pen pointer, if we have it. for (var i = 0; i < m_PointerStates.length; ++i) { - ref var state = ref GetPointerStateForIndex(i); - // Touch pointers need to get forced to no longer be pressed otherwise they will not get released in subsequent frames. if (m_PointerStates[i].pointerType == UIPointerType.MouseOrPen) { SendPointerExitEventsAndRemovePointer(i);