Skip to content

Exceptions when allocating memory for native arrays from another thread in Unity #6

@octoberU

Description

@octoberU

It looks like Unity UnsafeUtility's Malloc doesn't like to be used outside of the main thread. I'm using UniTask's UniTask.SwitchToThreadPool(); to repro it.

Version Used: 0.2.2

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.
Cathei.LinqGen.Hidden.UnsafeUtils.ArrayAlloc[T] (System.Int32 size) (at Library/PackageCache/com.cathei.linqgen@81661744fc/Runtime/Unity/UnsafeUtils.cs:27)
Cathei.LinqGen.Hidden.DynamicArrayNative`1[T]..ctor (System.Int32 capacity) (at Library/PackageCache/com.cathei.linqgen@81661744fc/Runtime/Core/Collections/Native/DynamicArrayNative.cs:17)
Cathei.LinqGen.Hidden.PooledListNative`1[T]..ctor (System.Int32 capacity) (at Library/PackageCache/com.cathei.linqgen@81661744fc/Runtime/Core/Collections/Native/PooledListNative.cs:20)
Cathei.LinqGen.Hidden.ThenByKey_6`3+Enumerator[TSelector_6,TSelector_7,TSelector_8].InitState () (at LinqGen.Generator/Cathei.LinqGen.Generator.LinqGenSourceGenerator/LinqGen.1.cs:758)
Cathei.LinqGen.Hidden.ThenByKey_6`3+Enumerator[TSelector_6,TSelector_7,TSelector_8].MoveNext () (at LinqGen.Generator/Cathei.LinqGen.Generator.LinqGenSourceGenerator/LinqGen.1.cs:779)
TargetPreview.Scripts.Targets.Extensions.TargetCueExtensions.AsTargetCues (System.Collections.Generic.IEnumerable`1[T] cues) (at 

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions