Skip to content

Commit

Permalink
Merge pull request #209 from decline-cookies/writers-disable-safety
Browse files Browse the repository at this point in the history
CDFE and DBFE writers - Disable safety and document issue
  • Loading branch information
mbaker3 authored Apr 13, 2023
2 parents 1b707fb + e0918b2 commit 6295c06
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Scripts/Runtime/Entities/Data/CDFEWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ namespace Anvil.Unity.DOTS.Entities
[BurstCompatible]
public struct CDFEWriter<T> where T : struct, IComponentData
{
// TODO: #197 - Improve Safety. Currently unable to detect parallel writing from multiple jobs.
// Required to allow JobPart patterns
[NativeDisableContainerSafetyRestriction] [NativeDisableParallelForRestriction]
private ComponentDataFromEntity<T> m_CDFE;

Expand Down
12 changes: 11 additions & 1 deletion Scripts/Runtime/Entities/Data/DBFEForExclusiveWrite.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Entities;

namespace Anvil.Unity.DOTS.Entities
Expand All @@ -10,10 +11,19 @@ namespace Anvil.Unity.DOTS.Entities
/// To be used in jobs that allow for updating a specific instance in the DBFE
/// </summary>
/// <typeparam name="T">The type of <see cref="IBufferElementData"/> to update.</typeparam>
/// <remarks>
/// NOTE: The <see cref="BufferFromEntity{T}"/> has the
/// <see cref="NativeDisableContainerSafetyRestrictionAttribute"/> applied meaning that Unity will not issue
/// safety warnings when using it in jobs. This is because there might be many jobs of the same type but
/// representing different <see cref="AbstractTaskDriver"/>s and Unity's safety system gets upset if you straddle
/// across the jobs.
/// </remarks>
[BurstCompatible]
public struct DBFEForExclusiveWrite<T> where T : struct, IBufferElementData
{
[NativeDisableParallelForRestriction] [WriteOnly]
// TODO: #197 - Improve Safety. Currently unable to detect parallel writing from multiple jobs.
// Required to allow JobPart patterns
[NativeDisableContainerSafetyRestriction] [NativeDisableParallelForRestriction] [WriteOnly]
private BufferFromEntity<T> m_DBFE;

public DBFEForExclusiveWrite(SystemBase system)
Expand Down

0 comments on commit 6295c06

Please sign in to comment.