Skip to content

Commit 6ae2acc

Browse files
author
Rene Damm
authored
FIX: InlinedArray.RemoveAt sometimes removing the wrong element (case 1196143, #945).
1 parent d3baa87 commit 6ae2acc

File tree

8 files changed

+66
-8
lines changed

8 files changed

+66
-8
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using NUnit.Framework;
4+
using UnityEngine.InputSystem.Utilities;
5+
6+
public class InlinedArrayTests
7+
{
8+
[Test]
9+
[Category("Utilities")]
10+
[TestCase(1, 0)]
11+
[TestCase(2, 0)]
12+
[TestCase(3, 0)]
13+
[TestCase(2, 1)]
14+
[TestCase(3, 1)]
15+
[TestCase(3, 2)]
16+
[TestCase(10, 0)]
17+
[TestCase(10, 5)]
18+
[TestCase(10, 9)]
19+
public void Utilities_InlinedArray_CanRemoveElementAtIndex(int count, int removeAt)
20+
{
21+
var comparisonList = new List<string>();
22+
var array = new InlinedArray<string>();
23+
24+
for (var i = 0; i < count; ++i)
25+
{
26+
comparisonList.Add(i.ToString());
27+
array.Append(i.ToString());
28+
}
29+
30+
Assert.That(array.length, Is.EqualTo(comparisonList.Count));
31+
32+
array.RemoveAt(removeAt);
33+
comparisonList.RemoveAt(removeAt);
34+
35+
Assert.That(array, Is.EquivalentTo(comparisonList));
36+
}
37+
}

Assets/Tests/InputSystem/Utilities/InlinedArrayTests.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ however, it has to be formatted properly to pass verification tests.
1111

1212
### Fixed
1313

14+
- Fixed wrong event handlers getting removed when having three or more handlers on an event (case 1196143).
15+
* This was an bug in an internal data structure that impacted a number of code paths that were using the data structure.
1416
- Fixed `LayoutNotFoundException` being thrown when `InputControlPath.ToHumanReadableString` referenced a layout that could not be found.
1517

1618
## [1.0.0-preview.2] - 2019-11-4

Packages/com.unity.inputsystem/InputSystem/Actions/InputAction.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using UnityEngine.InputSystem.Utilities;
55
using UnityEngine.Serialization;
66

7+
////TODO: add way to retrieve the currently ongoing interaction and also add way to know how long it's been going on
8+
79
////FIXME: Whether a control from a binding that's part of a composite appears on an action is currently not consistently enforced.
810
//// If it mentions the action, it appears on the action. Otherwise it doesn't. The controls should consistently appear on the
911
//// action based on what action the *composite* references.
@@ -1091,6 +1093,8 @@ internal int BindingIndexOnActionToBindingIndexOnMap(int indexOfBindingOnAction)
10911093
$"Binding index {indexOfBindingOnAction} is out of range for action '{this}' with {currentBindingIndexOnAction + 1} bindings");
10921094
}
10931095

1096+
////TODO: make current event available in some form
1097+
10941098
/// <summary>
10951099
/// Information provided to action callbacks about what triggered an action.
10961100
/// </summary>

Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/InputValue.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.Diagnostics;
33

4+
////TODO: API to get the control and device from the internal context
5+
46
////TODO: ToString()
57

68
namespace UnityEngine.InputSystem

Packages/com.unity.inputsystem/InputSystem/Plugins/XR/Devices/Oculus.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Unity.XR.Oculus.Input
1414
public class OculusHMD : XRHMD
1515
{
1616
[Preserve]
17-
[InputControl(noisy = true)]
17+
[InputControl]
1818
[InputControl(name = "trackingState", layout = "Integer", aliases = new[] { "devicetrackingstate" })]
1919
[InputControl(name = "isTracked", layout = "Button", aliases = new[] { "deviceistracked" })]
2020
public ButtonControl userPresence { get; private set; }

Packages/com.unity.inputsystem/InputSystem/Plugins/XR/Devices/WindowsMR.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace UnityEngine.XR.WindowsMR.Input
1313
public class WMRHMD : XRHMD
1414
{
1515
[Preserve]
16-
[InputControl(noisy = true)]
16+
[InputControl]
1717
[InputControl(name = "devicePosition", layout = "Vector3", aliases = new[] { "HeadPosition" })]
1818
[InputControl(name = "deviceRotation", layout = "Quaternion", aliases = new[] { "HeadRotation" })]
1919
public ButtonControl userPresence { get; private set; }

Packages/com.unity.inputsystem/InputSystem/Utilities/InlinedArray.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public TValue this[int index]
6363
get
6464
{
6565
if (index < 0 || index >= length)
66-
throw new ArgumentOutOfRangeException("index");
66+
throw new ArgumentOutOfRangeException(nameof(index));
6767

6868
if (index == 0)
6969
return firstValue;
@@ -73,7 +73,7 @@ public TValue this[int index]
7373
set
7474
{
7575
if (index < 0 || index >= length)
76-
throw new ArgumentOutOfRangeException("index");
76+
throw new ArgumentOutOfRangeException(nameof(index));
7777

7878
if (index == 0)
7979
firstValue = value;
@@ -278,7 +278,7 @@ public void RemoveAt(int index)
278278
}
279279
else
280280
{
281-
firstValue = default(TValue);
281+
firstValue = default;
282282
}
283283
}
284284
else
@@ -300,17 +300,19 @@ public void RemoveAt(int index)
300300
{
301301
// Remove entry at beginning or in middle by pasting together
302302
// into a new array.
303-
var newAdditionalProcessors = new TValue[numAdditionalValues - 1];
303+
var newAdditionalValues = new TValue[numAdditionalValues - 1];
304304
if (index >= 2)
305305
{
306306
// Copy elements before entry.
307-
Array.Copy(additionalValues, 0, newAdditionalProcessors, 0, index - 1);
307+
Array.Copy(additionalValues, 0, newAdditionalValues, 0, index - 1);
308308
}
309309

310310
// Copy elements after entry. We already know that we're not removing
311311
// the last entry so there have to be entries.
312-
Array.Copy(additionalValues, index + 1 - 1, newAdditionalProcessors, index - 1,
312+
Array.Copy(additionalValues, index + 1 - 1, newAdditionalValues, index - 1,
313313
length - index - 1);
314+
315+
additionalValues = newAdditionalValues;
314316
}
315317
}
316318

0 commit comments

Comments
 (0)