Search Issue Tracker

Fixed in 2022.1.X

Fixed in 2019.4.X, 2020.3.X, 2021.3.X

Votes

8

Found in

2019.4

2020.3

2020.3.12f1

2021.1

2021.2

2022.1

Issue ID

1348778

Regression

No

[InputSystem] QueueStateEvent exceptions when it is being called from another thread

Input

-

Reproduction steps:
1. Open the attached project from the google drive link
2. Go to Assets > Scenes > "SampleScene.unity"
3. Enter Play Mode

Expected result: No error exceptions in the console window
Actual result: Error exceptions in the console window

Reproducible with: 1.0.0-preview.2, 1.0.2, 1.1.0-preview.3 (2019.4.29f1, 2020.3.15f1, 2021.1.16f1), 1.1.0-pre.5 (2021.2.0b5, 2022.1.0a3)

  1. Resolution Note (fix version 2022.1):

    Fixed in 2022.1.0a15

  2. Resolution Note (fix version 2021.3):

    Fixed in 1.3.0

  3. Resolution Note (fix version 2020.3):

    Fixed in: 2020.3.37f1

Comments (3)

  1. Luzifix-de

    Nov 02, 2024 12:21

    The issue still exists and in 2021.3.44f

    Assertion failed on expression: 'gCurrentManagedTempMem != NULL'
    UnityEngine.StackTraceUtility:ExtractStackTrace ()
    Unity.Collections.NativeArray`1<byte>:Allocate (int,Unity.Collections.Allocator,Unity.Collections.NativeArray`1<byte>&)
    Unity.Collections.NativeArray`1<byte>:.ctor (int,Unity.Collections.Allocator,Unity.Collections.NativeArrayOptions)
    UnityEngine.InputSystem.InputSystem:QueueStateEvent<UnityEngine.InputSystem.LowLevel.GamepadState> (UnityEngine.InputSystem.InputDevice,UnityEngine.InputSystem.LowLevel.GamepadState,double)
    ShadowGroveGames.TouchLinkInput.Scripts.TouchLinkInputDevice:ProcessInputMessage (ShadowGroveGames.TouchLinkInput.Scripts.Structs.WebSocketMessages.Client.InputClientMessage) (at Assets/ShadowGroveGames/Touch Link Input/Scripts/TouchLinkInputDevice.cs:130)
    ShadowGroveGames.TouchLinkInput.Scripts.Communication.Endpoints.TouchLinkInputMessageHandler:HandleInput (ShadowGroveGames.TouchLinkInput.Scripts.Structs.WebSocketMessages.Client.InputClientMessage,ShadowGroveGames.SimpleWebSocketServer.Scripts.WebSocketServer.WebSocketEventArg) (at Assets/ShadowGroveGames/Touch Link Input/Scripts/Communication/MessageHandler/TouchLinkInputMessageHandler.cs:72)
    ShadowGroveGames.TouchLinkInput.Scripts.Communication.Endpoints.TouchLinkInputMessageHandler:OnData (ShadowGroveGames.TouchLinkInput.Scripts.Structs.WebSocketClientBaseMessage,ShadowGroveGames.SimpleWebSocketServer.Scripts.WebSocketServer.WebSocketEventArg) (at Assets/ShadowGroveGames/Touch Link Input/Scripts/Communication/MessageHandler/TouchLinkInputMessageHandler.cs:59)
    ShadowGroveGames.TouchLinkInput.Scripts.Communication.Server.TouchLinkInputWebSocketServer:ProcessEvents () (at Assets/ShadowGroveGames/Touch Link Input/Scripts/Communication/Server/TouchLinkInputWebSocketServer.cs:189)
    System.Threading.ThreadHelper:ThreadStart ()

  2. JakobAnarkyLabs

    Sep 05, 2024 07:19

    I am still getting this error in 2022.3.10 after having queued a certain amount of events in a non-main thread.

    It is pretty easily reproducible by, for example in a script like this:

    using System.Threading;
    using System.Threading.Tasks;
    using UnityEngine;
    using UnityEngine.InputSystem;

    public class Test : MonoBehaviour
    {
    Gamepad gamepad;
    CancellationTokenSource onDestroyCancellation = new();

    void Start()
    {
    gamepad = InputSystem.AddDevice<Gamepad>();

    Task.Run(async () =>
    {
    var ct = onDestroyCancellation.Token;
    while (!ct.IsCancellationRequested)
    {
    await Task.Delay(10);//Wait 10 milliseconds

    for (int i = 0; i < 50; i++)//Queue up 50 delta state events (can also just be state events)
    {
    InputSystem.QueueDeltaStateEvent(gamepad.leftStick, new Vector2(1, 1));
    }
    }
    });
    }

    void OnDestroy()
    {
    onDestroyCancellation.Cancel();
    }
    }

    I admit that 50 events per 10 milliseconds is quite a lot. If I decrease the amount to 10 events per 10 milliseconds (1 event per millisecond - still quite a lot) I sometimes get the error, sometimes not. But it is not very reassuring that this error CAN occur - I don't dare to queue up the events in another thread.

  3. massivevr

    Feb 02, 2022 11:59

    Tried in 2022.1.0b5 and now got:

    Assertion failed on expression: 'gCurrentManagedTempMem != NULL'
    UnityEngine.StackTraceUtility:ExtractStackTrace ()
    Unity.Collections.NativeArray`1<byte>:Allocate (int,Unity.Collections.Allocator,Unity.Collections.NativeArray`1<byte>&)
    Unity.Collections.NativeArray`1<byte>:.ctor (int,Unity.Collections.Allocator,Unity.Collections.NativeArrayOptions)
    UnityEngine.InputSystem.InputSystem:QueueStateEvent<MASSIVE.InputSystem.DeviceModules.Shimmer.Shimmer3DeviceState> (UnityEngine.InputSystem.InputDevice,MASSIVE.InputSystem.DeviceModules.Shimmer.Shimmer3DeviceState,double)
    MASSIVE.InputSystem.DeviceModules.Shimmer.ShimmerModule:ProcessData (ShimmerAPI.CustomEventArgs) (at Assets/MASSIVE/InputSystem/Devices/Shimmer/Scripts2/ShimmerModule.cs:488)
    MASSIVE.InputSystem.DeviceModules.Shimmer.ShimmerModule:HandleShimmerEvent (object,System.EventArgs) (at Assets/MASSIVE/InputSystem/Devices/Shimmer/Scripts2/ShimmerModule.cs:224)
    ShimmerAPI.ShimmerBluetooth:OnNewEvent (System.EventArgs) (at Assets/MASSIVE/InputSystem/Devices/Shimmer/Plugins/ShimmerAPI/ShimmerBluetooth.cs:6201)
    ShimmerAPI.ShimmerBluetooth:ReadData () (at Assets/MASSIVE/InputSystem/Devices/Shimmer/Plugins/ShimmerAPI/ShimmerBluetooth.cs:1121)
    System.Threading.ThreadHelper:ThreadStart ()

    and:

    ArgumentException: Could not allocate native memory. If this allocation was made from a managed thread outside of a job, you must use Allocator.Persistent or Allocator.TempJob.
    Unity.Collections.NativeArray`1[T].Allocate (System.Int32 length, Unity.Collections.Allocator allocator, Unity.Collections.NativeArray`1[T]& array) (at <aba06c866efd427898fe6d5a65b8962a>:0)
    Unity.Collections.NativeArray`1[T]..ctor (System.Int32 length, Unity.Collections.Allocator allocator, Unity.Collections.NativeArrayOptions options) (at <aba06c866efd427898fe6d5a65b8962a>:0)
    UnityEngine.InputSystem.LowLevel.InputEventBuffer.AllocateEvent (System.Int32 sizeInBytes, System.Int32 capacityIncrementInBytes, Unity.Collections.Allocator allocator) (at Library/PackageCache/com.unity.inputsystem@1.3.0/InputSystem/Events/InputEventBuffer.cs:214)
    UnityEngine.InputSystem.LowLevel.InputEventBuffer.AppendEvent (UnityEngine.InputSystem.LowLevel.InputEvent* eventPtr, System.Int32 capacityIncrementInBytes, Unity.Collections.Allocator allocator) (at Library/PackageCache/com.unity.inputsystem@1.3.0/InputSystem/Events/InputEventBuffer.cs:171)
    UnityEngine.InputSystem.LowLevel.InputEventStream.Write (UnityEngine.InputSystem.LowLevel.InputEvent* eventPtr) (at Library/PackageCache/com.unity.inputsystem@1.3.0/InputSystem/Events/InputEventStream.cs:99)
    UnityEngine.InputSystem.InputManager.QueueEvent (UnityEngine.InputSystem.LowLevel.InputEvent* eventPtr) (at Library/PackageCache/com.unity.inputsystem@1.3.0/InputSystem/InputManager.cs:1739)
    UnityEngine.InputSystem.InputManager.QueueEvent[TEvent] (TEvent& inputEvent) (at Library/PackageCache/com.unity.inputsystem@1.3.0/InputSystem/InputManager.cs:1756)
    UnityEngine.InputSystem.InputSystem.QueueStateEvent[TState] (UnityEngine.InputSystem.InputDevice device, TState state, System.Double time) (at Library/PackageCache/com.unity.inputsystem@1.3.0/InputSystem/InputSystem.cs:2590)
    MASSIVE.InputSystem.DeviceModules.Shimmer.ShimmerModule.ProcessData (ShimmerAPI.CustomEventArgs args) (at Assets/MASSIVE/InputSystem/Devices/Shimmer/Scripts2/ShimmerModule.cs:488)
    MASSIVE.InputSystem.DeviceModules.Shimmer.ShimmerModule.HandleShimmerEvent (System.Object sender, System.EventArgs args) (at Assets/MASSIVE/InputSystem/Devices/Shimmer/Scripts2/ShimmerModule.cs:224)
    ShimmerAPI.ShimmerBluetooth.OnNewEvent (System.EventArgs e) (at Assets/MASSIVE/InputSystem/Devices/Shimmer/Plugins/ShimmerAPI/ShimmerBluetooth.cs:6201)
    ShimmerAPI.ShimmerBluetooth.ReadData () (at Assets/MASSIVE/InputSystem/Devices/Shimmer/Plugins/ShimmerAPI/ShimmerBluetooth.cs:1121)
    System.Threading.ThreadHelper.ThreadStart_Context (System.Object state) (at <cdc4992cc04a4e77a24a09cd121af77b>:0)
    System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <cdc4992cc04a4e77a24a09cd121af77b>:0)
    System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <cdc4992cc04a4e77a24a09cd121af77b>:0)
    System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) (at <cdc4992cc04a4e77a24a09cd121af77b>:0)
    System.Threading.ThreadHelper.ThreadStart () (at <cdc4992cc04a4e77a24a09cd121af77b>:0)
    UnityEngine.<>c:<RegisterUECatcher>b__0_0(Object, UnhandledExceptionEventArgs)
    Unity.Collections.LowLevel.Unsafe.UnsafeUtility:Malloc(Int64, Int32, Allocator)
    Unity.Collections.NativeArray`1:Allocate(Int32, Allocator, NativeArray`1&)
    Unity.Collections.NativeArray`1:.ctor(Int32, Allocator, NativeArrayOptions)
    UnityEngine.InputSystem.InputSystem:QueueStateEvent(InputDevice, Shimmer3DeviceState, Double)
    MASSIVE.InputSystem.DeviceModules.Shimmer.ShimmerModule:ProcessData(CustomEventArgs) (at Assets/MASSIVE/InputSystem/Devices/Shimmer/Scripts2/ShimmerModule.cs:488)
    MASSIVE.InputSystem.DeviceModules.Shimmer.ShimmerModule:HandleShimmerEvent(Object, EventArgs) (at Assets/MASSIVE/InputSystem/Devices/Shimmer/Scripts2/ShimmerModule.cs:224)
    ShimmerAPI.ShimmerBluetooth:OnNewEvent(EventArgs) (at Assets/MASSIVE/InputSystem/Devices/Shimmer/Plugins/ShimmerAPI/ShimmerBluetooth.cs:6201)
    ShimmerAPI.ShimmerBluetooth:ReadData() (at Assets/MASSIVE/InputSystem/Devices/Shimmer/Plugins/ShimmerAPI/ShimmerBluetooth.cs:1121)
    System.Threading.ThreadHelper:ThreadStart()

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.