diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index bf42c7171d..7479fcbc14 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -22,6 +22,7 @@ however, it has to be formatted properly to pass verification tests. - Fixed Inspector Window being refreshed all the time when a PlayerInput component is present with Invoke Unity Events nofication mode chosen [ISXB-1448](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1448) - Fixed an issue where an action with a name containing a slash "/" could not be found via `InputActionAsset.FindAction(string,bool)`. [ISXB-1306](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1306). - Fixed Gamepad stick up/down inputs that were not recognized in WebGL. [ISXB-1090](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1090) +- Fixed reenabling the VirtualMouseInput component may sometimes lead to NullReferenceException. [ISXB-1096](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1096) - Fixed PlayerInput component automatically switching away from the default ActionMap set to 'None'. - Fixed a console error being shown when targeting visionOS builds in 2022.3. - Fixed a Tap Interaction issue with analog controls. The Tap interaction would keep re-starting after timeout. [ISXB-627](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-627) diff --git a/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionState.cs b/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionState.cs index fe8df0911c..3301e62432 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionState.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionState.cs @@ -593,7 +593,8 @@ private void RestoreActionStatesAfterReResolvingBindings(UnmanagedMemory oldStat if (newBindingState.isComposite) { var compositeIndex = newBindingState.compositeOrCompositeBindingIndex; - memory.compositeMagnitudes[compositeIndex] = oldState.compositeMagnitudes[compositeIndex]; + if (oldState.compositeMagnitudes != null) + memory.compositeMagnitudes[compositeIndex] = oldState.compositeMagnitudes[compositeIndex]; } var actionIndex = newBindingState.actionIndex; @@ -872,7 +873,8 @@ public void ResetActionState(int actionIndex, InputActionPhase toPhase = InputAc // Wipe state. actionState->phase = toPhase; actionState->controlIndex = kInvalidIndex; - actionState->bindingIndex = memory.actionBindingIndices[memory.actionBindingIndicesAndCounts[actionIndex]]; + var idx = memory.actionBindingIndicesAndCounts[actionIndex]; + actionState->bindingIndex = memory.actionBindingIndices != null ? memory.actionBindingIndices[idx] : 0; actionState->interactionIndex = kInvalidIndex; actionState->startTime = 0; actionState->time = 0; @@ -2879,6 +2881,9 @@ internal TValue ReadValue(int bindingIndex, int controlIndex, bool ignor internal TValue ApplyProcessors(int bindingIndex, TValue value, InputControl controlOfType = null) where TValue : struct { + if (totalBindingCount == 0) + return value; + var processorCount = bindingStates[bindingIndex].processorCount; if (processorCount > 0) { @@ -4139,6 +4144,16 @@ public struct UnmanagedMemory : IDisposable public ActionMapIndices* mapIndices; + private static byte* AllocFromBlob(ref byte* top, int size) + { + if (size == 0) + return null; + + var allocation = top; + top += size; + return allocation; + } + public void Allocate(int mapCount, int actionCount, int bindingCount, int controlCount, int interactionCount, int compositeCount) { Debug.Assert(basePtr == null, "Memory already allocated! Free first!"); @@ -4164,17 +4179,17 @@ public void Allocate(int mapCount, int actionCount, int bindingCount, int contro // NOTE: This depends on the individual structs being sufficiently aligned in order to not // cause any misalignment here. TriggerState, InteractionState, and BindingState all // contain doubles so put them first in memory to make sure they get proper alignment. - actionStates = (TriggerState*)ptr; ptr += actionCount * sizeof(TriggerState); - interactionStates = (InteractionState*)ptr; ptr += interactionCount * sizeof(InteractionState); - bindingStates = (BindingState*)ptr; ptr += bindingCount * sizeof(BindingState); - mapIndices = (ActionMapIndices*)ptr; ptr += mapCount * sizeof(ActionMapIndices); - controlMagnitudes = (float*)ptr; ptr += controlCount * sizeof(float); - compositeMagnitudes = (float*)ptr; ptr += compositeCount * sizeof(float); - controlIndexToBindingIndex = (int*)ptr; ptr += controlCount * sizeof(int); - controlGroupingAndComplexity = (ushort*)ptr; ptr += controlCount * sizeof(ushort) * 2; - actionBindingIndicesAndCounts = (ushort*)ptr; ptr += actionCount * sizeof(ushort) * 2; - actionBindingIndices = (ushort*)ptr; ptr += bindingCount * sizeof(ushort); - enabledControls = (int*)ptr; ptr += (controlCount + 31) / 32 * sizeof(int); + actionStates = (TriggerState*)AllocFromBlob(ref ptr, actionCount * sizeof(TriggerState)); + interactionStates = (InteractionState*)AllocFromBlob(ref ptr, interactionCount * sizeof(InteractionState)); + bindingStates = (BindingState*)AllocFromBlob(ref ptr, bindingCount * sizeof(BindingState)); + mapIndices = (ActionMapIndices*)AllocFromBlob(ref ptr, mapCount * sizeof(ActionMapIndices)); + controlMagnitudes = (float*)AllocFromBlob(ref ptr, controlCount * sizeof(float)); + compositeMagnitudes = (float*)AllocFromBlob(ref ptr, compositeCount * sizeof(float)); + controlIndexToBindingIndex = (int*)AllocFromBlob(ref ptr, controlCount * sizeof(int)); + controlGroupingAndComplexity = (ushort*)AllocFromBlob(ref ptr, controlCount * sizeof(ushort) * 2); + actionBindingIndicesAndCounts = (ushort*)AllocFromBlob(ref ptr, actionCount * sizeof(ushort) * 2); + actionBindingIndices = (ushort*)AllocFromBlob(ref ptr, bindingCount * sizeof(ushort)); + enabledControls = (int*)AllocFromBlob(ref ptr, (controlCount + 31) / 32 * sizeof(int)); } public void Dispose()