Repository navigation
FIX: [IN-158913] Fixed action state monitors left behind when disposed under another InputManager - #2511
Draft
josepmariapujol-unity wants to merge 1 commit into
Draft
FIX: [IN-158913] Fixed action state monitors left behind when disposed under another InputManager#2511josepmariapujol-unity wants to merge 1 commit into
josepmariapujol-unity wants to merge 1 commit into
Conversation
…d under another InputManager InputActionState removed its state change monitors and timeouts from InputSystem.manager, which is not always the manager they were added to. When Play Mode stopped during an InputTestFixture test, UI Toolkit shut down the InputForUI provider before the fixture restored the real InputManager. The provider's actions were disposed and their memory freed, but their monitors stayed in the real manager. With domain reload disabled, every mouse move in the next Play Mode session then threw a NullReferenceException from the freed InputActionState. The state now records the manager it installs monitors in and removes monitors and timeouts from that manager. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
With domain reload disabled, stopping Play Mode while an
InputTestFixtureplay mode test is running can leave the editor throwing aNullReferenceExceptionfromInputActionState+BindingState.get_actionIndexon every mouse move in the next Play Mode session. Three asserts come first each time:Map index out of range,Control index out of rangeandBinding index out of range.The cause is that
InputActionStateadds its state change monitors toInputSystem.managerand later removes them fromInputSystem.manager. These are not always the same manager. When the project has a UI Toolkit panel in Play Mode:InputSystemProvider) enables the UI map of its ownDefaultInputActionson the realInputManager.InputTestFixture.Setupinstalls a temporaryInputManager.ExitingPlayModehandlers run in subscription order. UI Toolkit's handler was registered when the editor loaded, so it runs first and shuts down the provider. The provider disables its UI map and disposesDefaultInputActionswhile the fixture's manager is still installed. The monitors are removed from the fixture's manager, which doesn't have them, and the action state's memory is freed.InputActionStatenow records theInputManagerit installs its monitors in, and removes monitors and timeouts from that manager. If none of the state's controls are enabled, enabling picks the current manager as before. If some are already enabled, new monitors join the existing ones in the same manager, so all of them can be removed together later.The initial-state-check
onBeforeUpdatehook still usesInputSystem.manager. It cannot cause these errors, so it is not part of this change.Testing status & QA
CoreTests.Actions_DisposingActionWhileAnotherInputManagerIsInstalled_RemovesItsStateMonitors. It enables an action, installs a secondInputManager, disposes the action, switches back, checks that no monitor of the disposed state is left, and presses the bound button. Without the fix it fails because the disposed state is still monitoring the original manager.InputActionsEditorTests(editor window focus and rename timing). The same class also has failures ondevelopwithout this change, so they appear unrelated.UIDocumentin the scene, start anInputTestFixture[UnityTest]that yields for a while, stop Play Mode during the test, then enter Play Mode again and move the mouse over the Game view. No errors should be logged.Overall Product Risks
InputTestFixture, remoting tests): new monitors for a state that already has monitors in another manager now join them instead of going to the current manager.Comments to reviewers
HasEnabledControls()scans the enabled-controls bitfield once perEnableControlscall. That is one 32-bit word per 32 controls, and it runs only when actions are enabled.m_MonitorManageris not cleared when every control is disabled, soStopTimeoutcalls made afterDisableControlsstill go to the manager that has the timeouts.InputSystemProvider.Shutdownunsubscribes fromInputSystem.onActionsChangeon whichever manager is current, so the real manager can keep a callback into a provider that has been shut down.This description, the fix and the test were written by an AI agent (Claude Code, Claude Opus 5.5) working for the PR author.
Checklist
Before review:
Changed,Fixed,Addedsections.Area_CanDoX,Area_CanDoX_EvenIfYIsTheCase,Area_WhenIDoX_AndYHappens_ThisIsTheResult.During merge:
NEW: ___.FIX: ___.DOCS: ___.CHANGE: ___.RELEASE: 1.1.0-preview.3.🤖 Generated with Claude Code