Search Issue Tracker

By Design



Found in [Package]


Issue ID




NativeHashSet Capacity Accessor triggers exception when scheduled for jobs

Package: Burst


Steps to reproduce:
1. Open the attached user's project ""
2. Open the "SampleScene.unity"
3. Enter Play Mode
4. Observe the Console window

Expected results: NativeHashSet Capacity Accessor does not trigger an exception when scheduled for jobs
Actual results: NativeHashSet Capacity Accessor triggers an exception when scheduled for jobs

Reproducible on: Burst 1.6.6 - 1.8.2 (2020.3.41f1, 2021.3.15f1, 2022.2.1f1, 2023.1.0a23)

-Exception outputted:
InvalidOperationException: The previously scheduled job JobDependencyTest:GenerateIndices writes to the Unity.Collections.NativeHashSet`1[System.Int32] GenerateIndices.output.m_Data. You must call JobHandle.Complete() on the job JobDependencyTest:GenerateIndices, before you can deallocate the Unity.Collections.NativeHashSet`1[System.Int32] safely.
Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckDeallocateAndThrow (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle handle) (at <bae255e3e08e46f7bc2fbd23dde96338>:0)

  1. Resolution Note:

    This isn't a Burst bug, because the same thing happens with Burst disabled. And also, I don't think there's a bug here. The error message says correctly that you must call JobHandle.Complete() before disposing the output data used in the job. And I think the user was aware of this, because the sample project contains a commented-out line that does the correct thing: generatorHandles[0].Complete();.

    Note that you must call Complete before accessing the NativeHashSet Capacity, because the job system has detected that the NativeHashSet is used in the job, so it's only safe to access it after the job has completed.

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.