diff --git a/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionState.cs b/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionState.cs index fe8df0911c..ed06d47b56 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionState.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionState.cs @@ -872,7 +872,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 +2880,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 +4143,19 @@ public struct UnmanagedMemory : IDisposable public ActionMapIndices* mapIndices; + // This is Anthony's version of block allocation from a blob + private 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 +4181,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()