Search Unity

Question NotSupportedException: Control count per binding cannot exceed byte.MaxValue=255

Discussion in 'Input System' started by codeimpossible, Dec 7, 2021.

  1. codeimpossible

    codeimpossible

    Joined:
    Mar 27, 2013
    Posts:
    9
    Whenever I run my Play Tests I eventually receive an exception during their execution:

    Once this error starts happening, it doesn't go away until I restart the Unity Editor. I think I am either using my InputActionAsset incorrectly or something isn't getting cleaned up as part of the test teardown or both. I'm not sure exactly what the issue is and I've dug into this a bit so far so I figured I'd reach out here to see if anyone else has run into this error before. I've included a stack trace below as well.

    Code (CSharp):
    1. UnityEngine.InputSystem.InputActionState+BindingState.set_controlCount (System.Int32 value) (at Library/PackageCache/com.unity.inputsystem@1.0.2/InputSystem/Actions/InputActionState.cs:2321)
    2. UnityEngine.InputSystem.InputBindingResolver.AddActionMap (UnityEngine.InputSystem.InputActionMap map) (at Library/PackageCache/com.unity.inputsystem@1.0.2/InputSystem/Actions/InputBindingResolver.cs:369)
    3. UnityEngine.InputSystem.InputActionAsset:Enable()
    4. Game.InputScheme:Enable() (at Assets/Scripts/InputScheme.cs:1160)
    5. Game.PlayerInput:OnEnable() (at Assets/Scripts/PlayerInput.cs:38)
    6. UnityEngine.Object:Instantiate(GameObject, Vector3, Quaternion)
    7. Game.Utilities.PlayerResolver:CreatePlayer(Vector2) (at Assets/Scripts/Utilities/PlayerUtility.cs:41)
    8. Game.Utilities.PlayerUtility:CreatePlayer(Vector2) (at Assets/Scripts/Utilities/PlayerUtility.cs:134)
    9. Game.<SpawnPlayer>d__15:MoveNext() (at Assets/Scripts/PlayerSpawner.cs:92)
    10. UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
    11. Game.PlayerSpawner:PrepareToSpawnPlayer() (at Assets/Scripts/PlayerSpawner.cs:80)
    12. Game.PlayerSpawner:OnLevelActivate(GameLevel) (at Assets/Scripts/PlayerSpawner.cs:66)
    13. Game.GameObjects.GameLevel:Activate() (at Assets/Scripts/GameObjects/GameLevel.cs:163)
    14. GameEditor.Tests.Integration.TestHelpers.LevelHelper:ActivateLevel(GameLevel) (at Assets/Tests/Editor/Integration/TestHelpers/LevelHelper.cs:9)
    15. GameEditor.Tests.Integration.AI.<WhenEnemyIsSpawned_ItWaitsInIdle>d__0:MoveNext() (at Assets/Tests/Editor/Integration/AI/EnemyAIBasicBehaviours.cs:45)
    16. UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
     
    migwellian likes this.
  2. migwellian

    migwellian

    Joined:
    Mar 20, 2018
    Posts:
    16
    I just started using the InputSystem TestFramework and I am getting the same error in my PlayMode tests.

    Unity version 2020.3.24f1.


    NotSupportedException: Control count per binding cannot exceed byte.MaxValue=255
    UnityEngine.InputSystem.InputActionState+BindingState.set_controlCount (System.Int32 value) (at Library/PackageCache/com.unity.inputsystem@1.2.0/InputSystem/Actions/InputActionState.cs:2828)
    UnityEngine.InputSystem.InputBindingResolver.AddActionMap (UnityEngine.InputSystem.InputActionMap map) (at Library/PackageCache/com.unity.inputsystem@1.2.0/InputSystem/Actions/InputBindingResolver.cs:383)
    UnityEngine.InputSystem.UI.InputSystemUIInputModule:OnEnable() (at Library/PackageCache/com.unity.inputsystem@1.2.0/InputSystem/Plugins/UI/InputSystemUIInputModule.cs:1378)
     
  3. migwellian

    migwellian

    Joined:
    Mar 20, 2018
    Posts:
    16
    Here is a simple test that reproduces the problem. With a fresh start of the Unity Editor I got the error after only 30 instances of this test running.

    Code (CSharp):
    1.    
    2.     // an array { 0, 1, 2, ... 260 }
    3.     static int[] iteration = Enumerable.Repeat(0, 260).Select((tr, ti) => tr + ti).ToArray();  
    4.  
    5.     [UnityTest]
    6.     public IEnumerator GamepadDoesntCleanUpProperly([ValueSource("iteration")] int dummy)
    7.     {
    8.         Gamepad gamepad = InputSystem.AddDevice<Gamepad>();
    9.         return null;
    10.     }
    11.  
     
  4. andrew_oc

    andrew_oc

    Unity Technologies

    Joined:
    Apr 16, 2021
    Posts:
    77
    I'm a bit confused by the sample code since it doesn't do anything with actions and shouldn't be hitting the part of the code that is in your stack trace. I do see InputSystemUIInputModule in there though. Any idea where that is being called from? What version of the input system package are you using?
     
  5. codeimpossible

    codeimpossible

    Joined:
    Mar 27, 2013
    Posts:
    9
    I'm using v1.0.2 of the input system package. This seems to be a bug in the input system where whenever you bind a new control using InputSystem.AddDevice<T>() it increments this counter, but never decrements it. I think i've managed to work around this by removing any bound controls in my test teardown with InputSystem.RemoveDevice<T>() but im not 100% sure this has worked. It would be nice to have what this limit is and when it gets incremented/decremented within the docs somewhere.
     
    migwellian likes this.
  6. andrew_oc

    andrew_oc

    Unity Technologies

    Joined:
    Apr 16, 2021
    Posts:
    77
    There have been a huge number of bug fixes between 1.0.2 and the latest package version (1.2 I think now), and I can't seem to reproduce this locally. Are you able to update the package and try on a newer version?
     
  7. migwellian

    migwellian

    Joined:
    Mar 20, 2018
    Posts:
    16
    I was already on Input System 1.2.0 so I can confirm that the bug is evident under this version using my sample code above. I am also on the latest version of Test Framework, 1.1.30.

    I can also confirm that the workaround that codeimpossible suggested (calling RemoveDevice in a [UnityTearDown] function) works for me.
     
  8. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Only if
    InputTestFixture
    is used will cleanup be performed automatically. Otherwise, a test will simply use the "live" version of the system and thus every
    AddDevice
    call in a test will simply keep adding devices that stick around until after the test.

    When not using
    InputTestFixture
    , any cleanup has to be performed manually.