Skip to content

Commit

Permalink
FIX: NullReferenceException when disabling actions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rene Damm committed Jul 2, 2018
1 parent 4e31287 commit 03b89a7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
9 changes: 6 additions & 3 deletions Packages/com.unity.inputsystem/InputSystem/InputManager.cs
Expand Up @@ -1342,12 +1342,15 @@ public void Remove(IInputStateChangeMonitor monitor, long monitorIndex)
return;

////REVIEW: would be better to clean these up implicitly during the next traversal
for (var i = 0; i < listeners.Length; ++i)
for (var i = 0; i < signalled.length; ++i)
if (ReferenceEquals(listeners[i].monitor, monitor) && listeners[i].monitorIndex == monitorIndex)
{
ArrayHelpers.EraseAt(ref listeners, i);
ArrayHelpers.EraseAt(ref memoryRegions, i);
var listenerCount = signalled.length;
var memoryRegionCount = signalled.length;
ArrayHelpers.EraseAtByMovingTail(listeners, ref listenerCount, i);
ArrayHelpers.EraseAtByMovingTail(memoryRegions, ref memoryRegionCount, i);
signalled.SetLength(signalled.length - 1);
break;
}
}

Expand Down
Expand Up @@ -328,9 +328,9 @@ public static bool Erase<TValue>(ref TValue[] array, TValue value)
/// <summary>
/// Erase an element from the array by moving the tail element into its place.
/// </summary>
/// <param name="array"></param>
/// <param name="count"></param>
/// <param name="index"></param>
/// <param name="array">Array to modify. May be not <c>null</c>.</param>
/// <param name="count">Current number of elements inside of array. May be less than <c>array.Length</c>.</param>
/// <param name="index">Index of element to remove. Tail element will get moved into its place.</param>
/// <typeparam name="TValue"></typeparam>
/// <remarks>
/// This method does not re-allocate the array. Instead <paramref name="count"/> is used
Expand All @@ -341,13 +341,15 @@ public static void EraseAtByMovingTail<TValue>(TValue[] array, ref int count, in
Debug.Assert(array != null);
Debug.Assert(index >= 0 && index < array.Length);
Debug.Assert(count >= 0 && count <= array.Length);
Debug.Assert(index < count);

// Move tail, if necessary.
if (index != count - 1)
array[index] = array[count - 1];

// Destroy current tail.
array[count - 1] = default(TValue);
if (count > 1)
array[count - 1] = default(TValue);
--count;
}

Expand Down

0 comments on commit 03b89a7

Please sign in to comment.