Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Assets/Tests/InputSystem/CoreTests_Actions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11663,6 +11663,42 @@ public void Actions_DisablingAllActions_RemovesAllTheirStateMonitors()
(InputManagerStateMonitors.StateChangeMonitorsForDevice x) => x.memoryRegions.All(r => r.sizeInBits == 0)));
}

// Stopping Play Mode during an InputTestFixture test disposed the InputForUI provider's actions while the fixture's
// InputManager was still installed, which left their state change monitors in the InputManager they were enabled in.
[Test]
[Category("Actions")]
public void Actions_DisposingActionWhileAnotherInputManagerIsInstalled_RemovesItsStateMonitors()
{
var gamepad = InputSystem.AddDevice<Gamepad>();
var action = new InputAction(binding: "<Gamepad>/buttonSouth");
action.Enable();
var state = action.m_ActionMap.m_State;

var manager = InputSystem.manager;
using (var otherRuntime = new InputTestRuntime())
{
var otherManager = InputManager.CreateAndInitialize(otherRuntime, null, fakeManagerForRemotingTests: true);
InputSystemTestHooks.TestHook_SwitchToDifferentInputManager(otherManager);
try
{
action.Dispose();
}
finally
{
// Dispose first: it resets the current state buffers, which switching back reinstalls.
otherManager.Dispose();
InputSystemTestHooks.TestHook_SwitchToDifferentInputManager(manager);
}
}

var monitors = manager.m_StateMonitors.m_MonitorsPerDevice[gamepad.m_DeviceIndex];
Assert.That(monitors.listeners.Take(monitors.count).Select(x => x.monitor), Has.None.SameAs(state));

// A monitor left behind would call into the action state whose memory Dispose() released.
Press(gamepad.buttonSouth);
LogAssert.NoUnexpectedReceived();
}

// https://fogbugz.unity3d.com/f/cases/1367442/
[Test]
[Category("Actions")]
Expand Down
1 change: 1 addition & 0 deletions Packages/com.unity.inputsystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed duplicate entries appearing in the Input Actions Editor binding path search for some devices, such as Mouse and XR controllers. [UUM-160646](https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-160646)
- Fixed closed Input Device Debugger windows staying in memory until the next domain reload. [ISX-3179]
- Fixed XR HMD device regeneration not copying the `canRunInBackground` parameter from its base layout, causing the XR app view to become locked to the tracking origin and frozen in place when the application regained focus after the headset went to sleep or a system menu was opened. [UUM-139700](https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-139700)
- Fixed a `NullReferenceException` on every mouse move in Play Mode after Play Mode was stopped during an `InputTestFixture` test with domain reload disabled. Actions disposed while another `InputManager` was installed left their state change monitors in the `InputManager` they were enabled in.

## [1.20.1] - 2026-10-05

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ private int GetControlBindingPriority(int controlIndex) =>
private bool m_InProcessControlStateChange;
private bool m_Suppressed;
private InputEventPtr m_CurrentlyProcessingThisEvent;
// The InputManager this state last installed its state change monitors in. Monitors and timeouts are removed
// from it rather than from InputSystem.manager, which can be a different manager by then, for example while
// InputTestFixture has its own manager installed.
private InputManager m_MonitorManager;
private Action m_OnBeforeUpdateDelegate;
private Action m_OnAfterUpdateDelegate;
private static readonly ProfilerMarker k_InputInitialActionStateCheckMarker = new ProfilerMarker("InitialActionStateCheck");
Expand Down Expand Up @@ -1109,7 +1113,7 @@ internal void OnActionPriorityChanged(InputAction action)
return;

var clampedPriority = (ushort)InputAction.ClampPriority(action.Priority);
var manager = InputSystem.manager;
var manager = monitorManager;
var bindingStartIndex = mapIndices[mapIndex].bindingStartIndex;
var bindingCount = mapIndices[mapIndex].bindingCount;
var bindingStatesPtr = memory.bindingStates;
Expand Down Expand Up @@ -1267,7 +1271,10 @@ private void EnableControls(int mapIndex, int controlStartIndex, int numControls
"Control start index out of range");
Debug.Assert(controlStartIndex + numControls <= totalControlCount, "Control range out of bounds");

var manager = InputSystem.manager;
// Keep all of this state's monitors in one manager, so that they can all be removed from it again.
if (!HasEnabledControls())
m_MonitorManager = InputSystem.manager;
var manager = m_MonitorManager;
for (var i = 0; i < numControls; ++i)
{
var controlIndex = controlStartIndex + i;
Expand Down Expand Up @@ -1304,7 +1311,7 @@ private void DisableControls(int mapIndex, int controlStartIndex, int numControl
"Control start index out of range");
Debug.Assert(controlStartIndex + numControls <= totalControlCount, "Control range out of bounds");

var manager = InputSystem.manager;
var manager = monitorManager;
for (var i = 0; i < numControls; ++i)
{
var controlIndex = controlStartIndex + i;
Expand Down Expand Up @@ -1355,13 +1362,25 @@ private void SetInitialStateCheckPending(BindingState* bindingStatePtr, bool val
}
}

// The manager holding this state's monitors, which its timeouts go to as well.
private InputManager monitorManager => m_MonitorManager ?? InputSystem.manager;

private bool IsControlEnabled(int controlIndex)
{
var intIndex = controlIndex / 32;
var mask = 1U << (controlIndex % 32);
return (enabledControls[intIndex] & mask) != 0;
}

private bool HasEnabledControls()
{
var intCount = (totalControlCount + 31) / 32;
for (var i = 0; i < intCount; ++i)
if (enabledControls[i] != 0)
return true;
return false;
}

private void SetControlEnabled(int controlIndex, bool state)
{
var intIndex = controlIndex / 32;
Expand Down Expand Up @@ -2292,7 +2311,7 @@ internal void StartTimeout(float seconds, ref TriggerState trigger)
Debug.Assert(trigger.controlIndex >= 0 && trigger.controlIndex < totalControlCount, "Control index out of range");
Debug.Assert(trigger.interactionIndex >= 0 && trigger.interactionIndex < totalInteractionCount, "Interaction index out of range");

var manager = InputSystem.manager;
var manager = monitorManager;
var currentTime = trigger.time;
var control = controls[trigger.controlIndex];
var interactionIndex = trigger.interactionIndex;
Expand Down Expand Up @@ -2321,7 +2340,7 @@ private void StopTimeout(int interactionIndex)

ref var interactionState = ref interactionStates[interactionIndex];

var manager = InputSystem.manager;
var manager = monitorManager;
manager.RemoveStateChangeMonitorTimeout(this, interactionState.timerMonitorIndex, interactionIndex);

// Update state.
Expand Down
Loading