InputSystem icon indicating copy to clipboard operation
InputSystem copied to clipboard

InvalidOperationException: Handle is not allocated

Open IronWarrior opened this issue 7 years ago • 3 comments

When running my project, often after I stop running I will get the following error:

image

With the following stack trace:

image

Which points to the following block of code:

       private void RemoveMapFromGlobalList()
        {
            var count = s_GlobalList.length;
            for (var i = 0; i < count; ++i)
                if (s_GlobalList[i].Target == this)
                {
                    s_GlobalList[i].Free();
                    s_GlobalList.RemoveAtByMovingTailWithCapacity(i);
                    break;
                }
        }

With this line being the offender s_GlobalList[i].Free();

According to the docs, GCHandle.Free throws an exception if you attempt to free a non-allocated handle, which is what I assume is happening here.

After this error has occured, no input from my XR device (Oculus Rift Touch Controllers) is listened to. Input from my gamepad and keyboard is correctly listened to. I've attached my relevant Input files below. I only started working with this system yesterday, so I doubt I'm doing anything super out of the ordinary.

Input.zip

IronWarrior avatar May 12 '19 00:05 IronWarrior

An update: started deleting everything one by one and was able to narrow down the cause. The exception is thrown whenever you have more than one instance of an IInputActionCollection instantiated and enabled.

Below is a very minimal project that reproduces the bug locally in 2019.1.2f1. I am running Windows 10. The exceptions I have in the image in my initial post get thrown roughly three quarters of the time, so running the main scene 2-3 times is enough to witness it. Deleting either of the InputTest objects results in the errors not being thrown.

If I make a workaround I will follow up with it here.

InputError.zip

IronWarrior avatar May 12 '19 06:05 IronWarrior

As a temporary fix, I use a singleton MonoBehaviour to manage a single instance of my InputActions that other classes retrieve at runtime. Using a MonoBehaviour (rather than a non-MB singleton) allows it to be destroyed at end of scene, clearing all of the events in it.

IronWarrior avatar May 13 '19 00:05 IronWarrior

Filed: https://issuetracker.unity3d.com/product/unity/issues/guid/1156869/ Closing.

JiaUnity avatar May 23 '19 00:05 JiaUnity