Skip to content

Commit 084bf22

Browse files
authored
FIX: ISXB-953 InputSystemProvider GC Alloc (#1973)
* Fixed isxb-953. Avoided memory allocation in InputSystemProvider.Update. * Updated Changelog with fix for isxb-953. * Added unit test for isxb-953.
1 parent a4285dc commit 084bf22

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

Assets/Tests/InputSystem/Plugins/InputForUITests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
using UnityEngine.InputSystem;
99
using UnityEngine.InputSystem.Controls;
1010
using UnityEngine.InputSystem.LowLevel;
11+
using UnityEngine.TestTools;
12+
using UnityEngine.TestTools.Constraints;
1113
#if UNITY_EDITOR
1214
using UnityEditor;
1315
using UnityEngine.InputSystem.Editor;
@@ -16,6 +18,7 @@
1618
using UnityEngine.TestTools;
1719
using Event = UnityEngine.InputForUI.Event;
1820
using EventProvider = UnityEngine.InputForUI.EventProvider;
21+
using Is = NUnit.Framework.Is;
1922

2023
// Note that these tests do not verify InputForUI default bindings at all.
2124
// It only verifies integration with Project-wide Input Actions.
@@ -682,6 +685,13 @@ public void ActionWithDifferentExpectedControlType_ShouldGenerateWarning(string
682685

683686
#endif // UNITY_EDITOR
684687

688+
[Test]
689+
public void Update_DoesntAllocate()
690+
{
691+
Update(); // Warm-up internals
692+
Assert.That(Update, Is.Not.AllocatingGCMemory());
693+
}
694+
685695
static void Update()
686696
{
687697
EventProvider.NotifyUpdate();

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ however, it has to be formatted properly to pass verification tests.
1010

1111
## [Unreleased] - yyyy-mm-dd
1212

13+
### Fixed
14+
- Fixed memory allocation on every frame when using UIDocument without EventSystem. [ISXB-953](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-953)
15+
1316
### Changed
1417
- Use `ProfilerMarker` instead of `Profiler.BeginSample` and `Profiler.EndSample` when appropriate to enable recording of profiling data.
1518

Packages/com.unity.inputsystem/InputSystem/Plugins/InputForUI/InputSystemProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public void Update()
127127
// This is necessary to ensure that events are dispatched in the correct order.
128128
// If all events are of the PointerEvents type, sorting is based on reverse order of the EventSource enum.
129129
// Touch -> Pen -> Mouse.
130-
m_Events.Sort(SortEvents);
130+
m_Events.Sort((a, b) => SortEvents(a, b));
131131

132132
var currentTime = (DiscreteTime)Time.timeAsRational;
133133

0 commit comments

Comments
 (0)