Input System crashes Runtime on Application Close

We are getting Input System related crashes whenever we close the application. Anyone experienced something similar ? Looks like it wants to access an action thats no longer there ;). Unity 2022.3.45f1 , Input System Package 1.11.0

Bugreport ID: IN-94027

Are you sure for all the events you subscribe to, you unsubscribe?

I did. But we have lots of packages and a pretty big codebase, something may have slipped the net. I tried to dispose the input maps that we use but that is not working either. Is there a reccomended way to ā€œshutdownā€ / dispose the internal state of the input system that i am not aware of?

well, with any luck you have some form of input manager, where all this is worked from, so you can just disabled it there ondisable/destory of that and/or disable it in your quit option. But because users love alt+f4, the disable/destroy should cover it

Those logs come right before the crash. Maybe someone knows where i need to look in order to find the issue.

Action count in old and new state must be the same
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Assert(Boolean, String)
UnityEngine.InputSystem.InputActionState:RestoreActionStatesAfterReResolvingBindings(UnmanagedMemory, InputControlList`1, Boolean) (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Actions\InputActionState.cs:541)
UnityEngine.InputSystem.InputActionState:FinishBindingResolution(Boolean, UnmanagedMemory, InputControlList`1, Boolean) (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Actions\InputActionState.cs:496)
UnityEngine.InputSystem.InputActionMap:ResolveBindings() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Actions\InputActionMap.cs:1391)
UnityEngine.InputSystem.InputActionMap:ResolveBindingsIfNecessary() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Actions\InputActionMap.cs:1237)
UnityEngine.InputSystem.InputActionState:DeferredResolutionOfBindings() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Actions\InputActionState.cs:4527)
UnityEngine.InputSystem.DeferBindingResolutionWrapper:Dispose() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Actions\InputActionRebindingExtensions.cs:2813)
UnityEngine.InputSystem.PlayerInput:OnDisable() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Plugins\PlayerInput\PlayerInput.cs:1748)

Map count in old and new state must be the same
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Assert(Boolean, String)
UnityEngine.InputSystem.InputActionState:RestoreActionStatesAfterReResolvingBindings(UnmanagedMemory, InputControlList`1, Boolean) (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Actions\InputActionState.cs:542)
UnityEngine.InputSystem.InputActionState:FinishBindingResolution(Boolean, UnmanagedMemory, InputControlList`1, Boolean) (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Actions\InputActionState.cs:496)
UnityEngine.InputSystem.InputActionMap:ResolveBindings() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Actions\InputActionMap.cs:1391)
UnityEngine.InputSystem.InputActionMap:ResolveBindingsIfNecessary() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Actions\InputActionMap.cs:1237)
UnityEngine.InputSystem.InputActionState:DeferredResolutionOfBindings() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Actions\InputActionState.cs:4527)
UnityEngine.InputSystem.DeferBindingResolutionWrapper:Dispose() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Actions\InputActionRebindingExtensions.cs:2813)
UnityEngine.InputSystem.PlayerInput:OnDisable() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Plugins\PlayerInput\PlayerInput.cs:1748)

Action map must be contained in state
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Assert(Boolean, String)
UnityEngine.InputSystem.InputActionState:FetchActionState(InputAction) (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Actions\InputActionState.cs:899)
UnityEngine.InputSystem.InputAction:get_currentState() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Actions\InputAction.cs:1649)
UnityEngine.InputSystem.InputAction:get_phase() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Actions\InputAction.cs:507)
UnityEngine.InputSystem.InputAction:get_enabled() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Actions\InputAction.cs:532)
UnityEngine.InputSystem.InputAction:Disable() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Actions\InputAction.cs:931)
UnityEngine.InputSystem.UI.InputSystemUIInputModule:TryDisableInputAction(InputActionReference, Boolean) (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Plugins\UI\InputSystemUIInputModule.cs:1650)
UnityEngine.InputSystem.UI.InputSystemUIInputModule:DisableAllActions() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Plugins\UI\InputSystemUIInputModule.cs:1598)
UnityEngine.InputSystem.UI.InputSystemUIInputModule:OnDisable() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Plugins\UI\InputSystemUIInputModule.cs:1549)

Action index is out of range
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Assert(Boolean, String)
UnityEngine.InputSystem.InputActionState:FetchActionState(InputAction) (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Actions\InputActionState.cs:900)
UnityEngine.InputSystem.InputAction:get_currentState() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Actions\InputAction.cs:1649)
UnityEngine.InputSystem.InputAction:get_phase() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Actions\InputAction.cs:507)
UnityEngine.InputSystem.InputAction:get_enabled() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Actions\InputAction.cs:532)
UnityEngine.InputSystem.InputAction:Disable() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Actions\InputAction.cs:931)
UnityEngine.InputSystem.UI.InputSystemUIInputModule:TryDisableInputAction(InputActionReference, Boolean) (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Plugins\UI\InputSystemUIInputModule.cs:1650)
UnityEngine.InputSystem.UI.InputSystemUIInputModule:DisableAllActions() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Plugins\UI\InputSystemUIInputModule.cs:1598)
UnityEngine.InputSystem.UI.InputSystemUIInputModule:OnDisable() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Plugins\UI\InputSystemUIInputModule.cs:1549)

Action map must be contained in state
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Assert(Boolean, String)
UnityEngine.InputSystem.InputActionState:DisableSingleAction(InputAction) (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Actions\InputActionState.cs:1073)
UnityEngine.InputSystem.InputAction:Disable() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Actions\InputAction.cs:934)
UnityEngine.InputSystem.UI.InputSystemUIInputModule:TryDisableInputAction(InputActionReference, Boolean) (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Plugins\UI\InputSystemUIInputModule.cs:1650)
UnityEngine.InputSystem.UI.InputSystemUIInputModule:DisableAllActions() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Plugins\UI\InputSystemUIInputModule.cs:1598)
UnityEngine.InputSystem.UI.InputSystemUIInputModule:OnDisable() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Plugins\UI\InputSystemUIInputModule.cs:1549)

Action map must be contained in state
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Assert(Boolean, String)
UnityEngine.InputSystem.InputActionState:DisableControls(InputAction) (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Actions\InputActionState.cs:1086)
UnityEngine.InputSystem.InputActionState:DisableSingleAction(InputAction) (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Actions\InputActionState.cs:1075)
UnityEngine.InputSystem.InputAction:Disable() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Actions\InputAction.cs:934)
UnityEngine.InputSystem.UI.InputSystemUIInputModule:TryDisableInputAction(InputActionReference, Boolean) (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Plugins\UI\InputSystemUIInputModule.cs:1650)
UnityEngine.InputSystem.UI.InputSystemUIInputModule:DisableAllActions() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Plugins\UI\InputSystemUIInputModule.cs:1598)
UnityEngine.InputSystem.UI.InputSystemUIInputModule:OnDisable() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Plugins\UI\InputSystemUIInputModule.cs:1549)

Action index out of range when disabling controls
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Assert(Boolean, String)
UnityEngine.InputSystem.InputActionState:DisableControls(InputAction) (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Actions\InputActionState.cs:1089)
UnityEngine.InputSystem.InputActionState:DisableSingleAction(InputAction) (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Actions\InputActionState.cs:1075)
UnityEngine.InputSystem.InputAction:Disable() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Actions\InputAction.cs:934)
UnityEngine.InputSystem.UI.InputSystemUIInputModule:TryDisableInputAction(InputActionReference, Boolean) (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Plugins\UI\InputSystemUIInputModule.cs:1650)
UnityEngine.InputSystem.UI.InputSystemUIInputModule:DisableAllActions() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Plugins\UI\InputSystemUIInputModule.cs:1598)
UnityEngine.InputSystem.UI.InputSystemUIInputModule:OnDisable() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Plugins\UI\InputSystemUIInputModule.cs:1549)

Map index out of range in DisableControls(InputAction)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Assert(Boolean, String)
UnityEngine.InputSystem.InputActionState:DisableControls(InputAction) (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Actions\InputActionState.cs:1094)
UnityEngine.InputSystem.InputActionState:DisableSingleAction(InputAction) (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Actions\InputActionState.cs:1075)
UnityEngine.InputSystem.InputAction:Disable() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Actions\InputAction.cs:934)
UnityEngine.InputSystem.UI.InputSystemUIInputModule:TryDisableInputAction(InputActionReference, Boolean) (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Plugins\UI\InputSystemUIInputModule.cs:1650)
UnityEngine.InputSystem.UI.InputSystemUIInputModule:DisableAllActions() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Plugins\UI\InputSystemUIInputModule.cs:1598)
UnityEngine.InputSystem.UI.InputSystemUIInputModule:OnDisable() (at .\Library\PackageCache\com.unity.inputsystem@1.11.0\InputSystem\Plugins\UI\InputSystemUIInputModule.cs:1549)

Crash!!!

Interestingly, this phrase appears a few times out there, and I found this Input system errors. Am I doing something wrong or is the input system broken? : r/Unity3D which mentions it seems to be caused by enable/disable of the input system, which we have all been lead to believe we need to do.

Now, as its not a problem Ive had myself, it seems odd, but I am wondering if it perhaps is caused by calling disable on it twice? hence when they removed it, it seemed to fix it, cos now its only done once…

Does it still occur if you remove the disables?

The Crash does not happen if i remove the ā€˜InputSystemUIInputModule’ from the build. It seems to be related to this module. In the Disable method of it, you can see that it tries to disable input actions that are no longer available.

OK, but thats not what I asked :stuck_out_tongue:

Yeah sorry - the linked thread does not lead to a solution. In general searching for hints on how to fix those errors/warnings leads into more deadends than anything helpful. I tried to disable everything that enables or diables Maps / Actions but that does not help either. However as i said i can clearly track this down to the OnDisbable() Method of the ā€˜InputSystemUIInputModule’. Since this one lives from game start till shutdown, there is no need for me to even have the functionality in the first place. So my hacky solution rn was to create a Script that inherits this class and overrides the OnDisable method. This seems to fix my crashes. But it is an ugly bandaid solution. Whatever the ā€˜user error’ on our side is - it would be nice if the application does not crash trying to access invalid memory but rather provide helpful information on the issue.

UPDATE: Switched from Input System 1.11.0 to 1.12.0 whicht results in a ā€œApplication not respondingā€ message on quit. Same setup that worked in the prior build on 1.11.0 (skipping the OnDisable), nothing changed just the Input System was updated.

Id say log a bug. While Ive not had the same, see if you can make a smaller version of your senario that does the sam and log it as a bug.

(I will warn you though, they are amazingly good at not being able to recreate issues)

@LeonhardP Could you please pass this information along to the Input System team?

I’m encountering a similar crash, but with a slightly different callstack. The crash occurs when I close the Windows 64-bit Standalone Player, with the following stack trace:

[Unity.InputSystem__1.cpp:25961] InputActionState_DisableControls_m8C6B11EE45D796B5CDFEA63F2806E2FFF34EA176 
[Unity.InputSystem__1.cpp:25653] InputActionState_DisableControls_m752949865C959C344B01849B9CF2D9B0FE15BABB 
[Unity.InputSystem__1.cpp:25415] InputActionState_DisableSingleAction_m998DDE29061E4548FBF5488C924FDC4F92732249 
[Unity.InputSystem.cpp:11528] InputAction_Disable_m72D1982F82457C6E003440BADD06989D399BDE50 
[Unity.InputSystem__8.cpp:25359] InputSystemUIInputModule_TryDisableInputAction_m6855DF4C580573A8EFD5CD0464C71820767DC8A2 
[Unity.InputSystem__8.cpp:24533] InputSystemUIInputModule_OnDisable_m3A7EF2B3E9E202A50760FAA193F40B17041BBB5B 

I managed to attach a debugger and step into InputActionState.DisableControls before the crash. The issue appears to be that InputActionState.enabledControls is NULL. Here’s the relevant code:

internal unsafe class InputActionState : IInputStateChangeMonitor, ICloneable, IDisposable
{
	public uint* enabledControls => (uint*)memory.enabledControls;

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

The crash happens when InputActionState.DisableControls calls InputActionState.IsControlEnabled, which attempts to read enabledControls while it’s NULL.

This results in a hard crash with the error: ā€œThe thread tried to read from or write to a virtual address for which it does not have the appropriate access.ā€

Unfortunately, I can’t provide a repro project, but I hope this information is enough for a Unity developer to investigate and address the issue.

I’m experiencing this in Unity 6000.1.13f1 with Input System 1.14.2, though I’ve seen it in earlier versions as well. Inheriting from InputSystemUIInputModule and skipping the calls to base.OnDestroy and base.OnDisable seems to work around the crash for me as well.

1 Like