Skip to content

Unity.Collections bug: Possible InvalidOperationException when using UnsafeTriangulator #333

@andywiecko

Description

@andywiecko

Unity.Collections@2.2+ has an unresolved bug, as you can read here:

...
All containers allocated with Allocator.Temp on the same thread use a shared AtomicSafetyHandle instance rather than each having their own.

This can lead to safety check error throws like this:

InvalidOperationException: The Unity.Collections.NativeList`1[System.Int32]
has been declared as [WriteOnly] in the job, but you are reading from it.

when using UnsafeTriangulator with Allocator.Temp. Consider the following example:

using var positions = new NativeList<double2>(Allocator.Temp);
positions.Add(...);

new UnsafeTriangulator().Triangulate(input: new(){ Positions = positions.AsArray() }, ...);

Unfortunately, due to AsArray() call, which should be safe, the above example will trigger an exception from the safety handle. Currently the only way to resolve this issue is:

I recommend the second option, calling ToArray, unless you are certain about what you are doing.

using var positions = new NativeList<double2>(Allocator.Temp);
positions.Add(...);

using var p = postions.ToArray(Allocator.Temp);
new UnsafeTriangulator().Triangulate(input: new(){ Positions = p }, ...);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions