Skip to content

Commit 25bf7e1

Browse files
authored
Merge branch 'develop' into use-debug-error-instead-assert-nda-packages
2 parents e4b86ec + 047bb8e commit 25bf7e1

File tree

4 files changed

+25
-98
lines changed

4 files changed

+25
-98
lines changed

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ however, it has to be formatted properly to pass verification tests.
3838
- Fixed an issue where batch jobs would fail with "Error: Error building Player because scripts are compiling" if a source generated .inputactions asset is out of sync with its generated source code (ISXB-1300).
3939
- Fixed multiple `OnScreenStick` Components that does not work together when using them simultaneously in isolation mode. [ISXB-813](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-813)
4040
- Fixed an issue in input actions editor window that caused certain fields in custom input composite bindings to require multiple clicks to action / focus. [ISXB-1171](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1171)
41+
- Fixed an editor/player hang in `InputSystemUIInputModule` due to an infinite loop. This was caused by the assumption that `RemovePointerAtIndex` would _always_ successfully remove the pointer, which is not the case with touch based pointers. [ISXB-1258](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1258)
4142

4243
### Changed
4344
- Changed location of the link xml file (code stripping rules), from a temporary directory to the project Library folder (ISX-2140).

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorState.cs

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#if UNITY_EDITOR && UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
22
using System;
33
using System.Collections.Generic;
4-
using System.Collections.ObjectModel;
54
using System.Linq;
65
using UnityEditor;
76

@@ -92,7 +91,6 @@ public InputActionsEditorState(
9291
int selectedActionIndex = 0,
9392
int selectedBindingIndex = 0,
9493
SelectionType selectionType = SelectionType.Action,
95-
Dictionary<(string, string), HashSet<int>> expandedBindingIndices = null,
9694
InputControlScheme selectedControlScheme = default,
9795
int selectedControlSchemeIndex = -1,
9896
int selectedDeviceRequirementIndex = -1,
@@ -112,9 +110,6 @@ public InputActionsEditorState(
112110
m_selectedControlSchemeIndex = selectedControlSchemeIndex;
113111
m_selectedDeviceRequirementIndex = selectedDeviceRequirementIndex;
114112

115-
m_ExpandedCompositeBindings = expandedBindingIndices == null ?
116-
new Dictionary<(string, string), HashSet<int>>() :
117-
new Dictionary<(string, string), HashSet<int>>(expandedBindingIndices);
118113
m_CutElements = cutElements;
119114
}
120115

@@ -201,12 +196,6 @@ public InputActionsEditorState(InputActionsEditorState other, SerializedObject a
201196
m_ControlScheme = new InputControlScheme();
202197
}
203198

204-
// Editor may leave these as null after domain reloads, so recreate them in that case.
205-
// If they exist, we attempt to just preserve the same expanded items based on name for now for simplicity.
206-
m_ExpandedCompositeBindings = other.m_ExpandedCompositeBindings == null ?
207-
new Dictionary<(string, string), HashSet<int>>() :
208-
new Dictionary<(string, string), HashSet<int>>(other.m_ExpandedCompositeBindings);
209-
210199
m_CutElements = other.cutElements;
211200
}
212201

@@ -218,7 +207,6 @@ public InputActionsEditorState With(
218207
InputControlScheme? selectedControlScheme = null,
219208
int? selectedControlSchemeIndex = null,
220209
int? selectedDeviceRequirementIndex = null,
221-
Dictionary<(string, string), HashSet<int>> expandedBindingIndices = null,
222210
List<CutElement> cutElements = null)
223211
{
224212
return new InputActionsEditorState(
@@ -228,7 +216,6 @@ public InputActionsEditorState With(
228216
selectedActionIndex ?? this.selectedActionIndex,
229217
selectedBindingIndex ?? this.selectedBindingIndex,
230218
selectionType ?? this.selectionType,
231-
expandedBindingIndices ?? m_ExpandedCompositeBindings,
232219

233220
// Control schemes
234221
selectedControlScheme ?? this.selectedControlScheme,
@@ -248,7 +235,6 @@ public InputActionsEditorState ClearCutElements()
248235
selectedActionIndex,
249236
selectedBindingIndex,
250237
selectionType,
251-
m_ExpandedCompositeBindings,
252238
selectedControlScheme,
253239
selectedControlSchemeIndex,
254240
selectedDeviceRequirementIndex,
@@ -262,39 +248,6 @@ public SerializedProperty GetActionMapByName(string actionMapName)
262248
.FirstOrDefault(p => p.FindPropertyRelative(nameof(InputActionMap.m_Name)).stringValue == actionMapName);
263249
}
264250

265-
public InputActionsEditorState ExpandCompositeBinding(SerializedInputBinding binding)
266-
{
267-
var key = GetSelectedActionMapAndActionKey();
268-
269-
var expandedCompositeBindings = new Dictionary<(string, string), HashSet<int>>(m_ExpandedCompositeBindings);
270-
if (!expandedCompositeBindings.TryGetValue(key, out var expandedStates))
271-
{
272-
expandedStates = new HashSet<int>();
273-
expandedCompositeBindings.Add(key, expandedStates);
274-
}
275-
276-
expandedStates.Add(binding.indexOfBinding);
277-
278-
return With(expandedBindingIndices: expandedCompositeBindings);
279-
}
280-
281-
public InputActionsEditorState CollapseCompositeBinding(SerializedInputBinding binding)
282-
{
283-
var key = GetSelectedActionMapAndActionKey();
284-
285-
if (m_ExpandedCompositeBindings.ContainsKey(key) == false)
286-
throw new InvalidOperationException("Trying to collapse a composite binding tree that was never expanded.");
287-
288-
// do the dance of C# immutability
289-
var oldExpandedCompositeBindings = m_ExpandedCompositeBindings;
290-
var expandedCompositeBindings = oldExpandedCompositeBindings.Keys.Where(dictKey => dictKey != key)
291-
.ToDictionary(dictKey => dictKey, dictKey => oldExpandedCompositeBindings[dictKey]);
292-
var newHashset = new HashSet<int>(m_ExpandedCompositeBindings[key].Where(index => index != binding.indexOfBinding));
293-
expandedCompositeBindings.Add(key, newHashset);
294-
295-
return With(expandedBindingIndices: expandedCompositeBindings);
296-
}
297-
298251
public InputActionsEditorState SelectAction(string actionName)
299252
{
300253
var actionMap = GetSelectedActionMap();
@@ -419,48 +372,11 @@ public readonly List<CutElement> GetCutElements()
419372
return m_CutElements;
420373
}
421374

422-
public ReadOnlyCollection<int> GetOrCreateExpandedState()
423-
{
424-
return new ReadOnlyCollection<int>(GetOrCreateExpandedStateInternal().ToList());
425-
}
426-
427-
private HashSet<int> GetOrCreateExpandedStateInternal()
428-
{
429-
var key = GetSelectedActionMapAndActionKey();
430-
431-
if (m_ExpandedCompositeBindings.TryGetValue(key, out var expandedStates))
432-
return expandedStates;
433-
434-
expandedStates = new HashSet<int>();
435-
m_ExpandedCompositeBindings.Add(key, expandedStates);
436-
return expandedStates;
437-
}
438-
439-
internal (string, string) GetSelectedActionMapAndActionKey()
440-
{
441-
var selectedActionMap = GetSelectedActionMap();
442-
443-
var selectedAction = selectedActionMap
444-
.FindPropertyRelative(nameof(InputActionMap.m_Actions))
445-
.GetArrayElementAtIndex(selectedActionIndex);
446-
447-
var key = (
448-
selectedActionMap.FindPropertyRelative(nameof(InputActionMap.m_Name)).stringValue,
449-
selectedAction.FindPropertyRelative(nameof(InputAction.m_Name)).stringValue
450-
);
451-
return key;
452-
}
453-
454375
private SerializedProperty GetSelectedActionMap()
455376
{
456377
return Selectors.GetActionMapAtIndex(serializedObject, selectedActionMapIndex)?.wrappedProperty;
457378
}
458379

459-
/// <summary>
460-
/// Expanded states for the actions tree view. These are stored per InputActionMap
461-
/// </summary>
462-
private readonly Dictionary<(string, string), HashSet<int>> m_ExpandedCompositeBindings;
463-
464380
private readonly InputControlScheme m_ControlScheme;
465381
}
466382

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionsTreeView.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,9 +659,12 @@ public static List<TreeViewItemData<ActionOrBindingData>> GetActionsAsTreeViewDa
659659

660660
private static int GetIdForGuid(Guid guid, Dictionary<Guid, int> idDictionary)
661661
{
662+
// This method is used to ensure that the same Guid always gets the same id
663+
// We use getHashCode instead of a counter, as we cannot guarantee that the same Guid will always be added in the same order
664+
// There is a tiny chance of a collision, but it is it does happen it will only affect the expanded state of the tree view
662665
if (!idDictionary.TryGetValue(guid, out var id))
663666
{
664-
id = idDictionary.Values.Count > 0 ? idDictionary.Values.Max() + 1 : 0;
667+
id = guid.GetHashCode();
665668
idDictionary.Add(guid, id);
666669
}
667670
return id;

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

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,9 +1662,11 @@ protected override void OnDisable()
16621662

16631663
private void ResetPointers()
16641664
{
1665-
var numPointers = m_PointerStates.length;
1666-
for (var i = 0; i < numPointers; ++i)
1667-
SendPointerExitEventsAndRemovePointer(0);
1665+
for (var i = 0; i < m_PointerStates.length; ++i)
1666+
{
1667+
if (SendPointerExitEventsAndRemovePointer(i))
1668+
--i;
1669+
}
16681670

16691671
m_CurrentPointerId = -1;
16701672
m_CurrentPointerIndex = -1;
@@ -2021,24 +2023,26 @@ private int AllocatePointer(int pointerId, int displayIndex, int touchId, UIPoin
20212023
return m_PointerStates.AppendWithCapacity(new PointerModel(eventData));
20222024
}
20232025

2024-
private void SendPointerExitEventsAndRemovePointer(int index)
2026+
// Returns true if the pointer was successfully removed (ISXB-1258)
2027+
private bool SendPointerExitEventsAndRemovePointer(int index)
20252028
{
20262029
var eventData = m_PointerStates[index].eventData;
20272030
if (eventData.pointerEnter != null)
20282031
ProcessPointerMovement(eventData, null);
20292032

2030-
RemovePointerAtIndex(index);
2033+
return RemovePointerAtIndex(index);
20312034
}
20322035

2033-
private void RemovePointerAtIndex(int index)
2036+
private bool RemovePointerAtIndex(int index)
20342037
{
20352038
Debug.Assert(m_PointerStates[index].eventData.pointerEnter == null, "Pointer should have exited all objects before being removed");
20362039

20372040
// 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()
20382041
ref var state = ref GetPointerStateForIndex(index);
20392042
if (state.pointerType == UIPointerType.Touch && (state.leftButton.isPressed || state.leftButton.wasReleasedThisFrame))
20402043
{
2041-
return;
2044+
// The pointer was not removed
2045+
return false;
20422046
}
20432047

20442048
// Retain event data so that we can reuse the event the next time we allocate a PointerModel record.
@@ -2086,6 +2090,8 @@ private void RemovePointerAtIndex(int index)
20862090
m_PointerStates.firstValue.eventData = eventData;
20872091
else
20882092
m_PointerStates.additionalValues[m_PointerStates.length - 1].eventData = eventData;
2093+
2094+
return true;
20892095
}
20902096

20912097
// Remove any pointer that no longer has the ability to point.
@@ -2100,8 +2106,9 @@ private void PurgeStalePointers()
21002106
!HaveControlForDevice(device, trackedDevicePosition) &&
21012107
!HaveControlForDevice(device, trackedDeviceOrientation)))
21022108
{
2103-
SendPointerExitEventsAndRemovePointer(i);
2104-
--i;
2109+
// Only decrement 'i' if the pointer was successfully removed
2110+
if (SendPointerExitEventsAndRemovePointer(i))
2111+
--i;
21052112
}
21062113
}
21072114

@@ -2310,8 +2317,8 @@ private void FilterPointerStatesByType()
23102317
}
23112318
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))
23122319
{
2313-
SendPointerExitEventsAndRemovePointer(i);
2314-
--i;
2320+
if (SendPointerExitEventsAndRemovePointer(i))
2321+
--i;
23152322
}
23162323
}
23172324
}
@@ -2322,8 +2329,8 @@ private void FilterPointerStatesByType()
23222329
{
23232330
if (m_PointerStates[i].pointerType == UIPointerType.MouseOrPen)
23242331
{
2325-
SendPointerExitEventsAndRemovePointer(i);
2326-
--i;
2332+
if (SendPointerExitEventsAndRemovePointer(i))
2333+
--i;
23272334
}
23282335
}
23292336
}

0 commit comments

Comments
 (0)