Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug DOTS Physics stops processing trigger events after reaching high entity count

Discussion in 'Physics for ECS' started by Reticulatas, Jun 30, 2022.

  1. Reticulatas

    Reticulatas

    Joined:
    Jul 31, 2012
    Posts:
    25
    com.unity.physics: 0.51.0-preview.32

    I'm having an issue that I can't seem to pin down.

    I have lots of bullets and enemies, very simple, all sphere colliders locked to the z-plane. Everything works fine until I hit around 10k+ entities and all trigger collisions begin to just not occur. This is very consistent. i have disabled almost every other system in the game and it still occurs.

    Here is my collision job:

    Code (CSharp):
    1.  
    2. [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
    3.     [UpdateAfter(typeof(ExportPhysicsWorld))]
    4.     [UpdateBefore(typeof(EndFramePhysicsSystem))]
    5.     public abstract partial class TriggerPhysicsSystemBase<T> : SystemBase where T : struct, ITriggerEventsJob
    6.     {
    7.         protected StepPhysicsWorld m_StepPhysicsWorld = default;
    8.  
    9.         protected override void OnCreate()
    10.         {
    11.             m_StepPhysicsWorld = World.GetOrCreateSystem<StepPhysicsWorld>();
    12.         }
    13.  
    14.         protected override void OnUpdate()
    15.         {
    16.             var collectTriggerEventsJob = CreateJob();
    17.  
    18.             collectTriggerEventsJob.Schedule(m_StepPhysicsWorld.Simulation, Dependency).Complete();
    19.         }
    20.  
    21.         protected abstract T CreateJob();
    22.     }
    Then the actual job system looks like:

    Code (CSharp):
    1.  
    2. [BurstCompile]
    3. public struct KillDoodTriggerJob : ITriggerEventsJob
    4. {
    5.     public EntityCommandBuffer commandBuffer;
    6.  
    7.     public ComponentDataFromEntity<BulletTag> bulletGroup;
    8.     [ReadOnly]
    9.     public ComponentDataFromEntity<DoodTag> doodGroup;
    10.     [ReadOnly]
    11.     public ComponentDataFromEntity<DestroyTag> destroyGroup;
    12.  
    13.     public EntityQueryMask IsBullet;
    14.     public EntityQueryMask IsDood;
    15.  
    16.     public void Execute(TriggerEvent triggerEvent)
    17.     {
    18.         Entity bullet;
    19.         Entity dood;
    20.  
    21.         if (PhysicsHelpers<BulletTag, DoodTag>.EventContains(triggerEvent, ref IsBullet, ref IsDood, out bullet, out dood))
    22.         {
    23.             if (!destroyGroup.HasComponent(dood)) // don't hit doods already marked for death
    24.             {
    25.                 commandBuffer.AddComponent(dood, new DestroyTag { });
    26.  
    27.                 var bulletData = bulletGroup[bullet];
    28.                 bulletData.Penetrations++;
    29.                 if (bulletData.Penetrations >= bulletData.BasePenetrations)
    30.                     commandBuffer.AddComponent(bullet, new DestroyTag { });
    31.                 commandBuffer.SetComponent(bullet, bulletData);
    32.             }
    33.         }
    34.     }
    35. }
    36.  
    37. public class KillDoodOnTriggerSystem : TriggerPhysicsSystemBase<KillDoodTriggerJob>
    38. {
    39.     private EndFixedStepSimulationEntityCommandBufferSystem m_CommandBufferSystem;
    40.  
    41.     private EntityQuery isBulletQuery;
    42.     private EntityQuery isDoodQuery;
    43.  
    44.     protected override void OnCreate()
    45.     {
    46.         m_CommandBufferSystem = World.GetOrCreateSystem<EndFixedStepSimulationEntityCommandBufferSystem>();
    47.  
    48.         isBulletQuery = EntityManager.CreateEntityQuery(typeof(BulletTag));
    49.         isDoodQuery = EntityManager.CreateEntityQuery(typeof(DoodTag));
    50.         base.OnCreate();
    51.     }
    52.  
    53.     protected override KillDoodTriggerJob CreateJob()
    54.     {
    55.         return new KillDoodTriggerJob()
    56.         {
    57.             commandBuffer = m_CommandBufferSystem.CreateCommandBuffer(),
    58.             bulletGroup = GetComponentDataFromEntity<BulletTag>(),
    59.             doodGroup = GetComponentDataFromEntity<DoodTag>(true),
    60.             destroyGroup = GetComponentDataFromEntity<DestroyTag>(true),
    61.             IsBullet = EntityManager.GetEntityQueryMask(isBulletQuery),
    62.             IsDood = EntityManager.GetEntityQueryMask(isDoodQuery)
    63.         };
    64.     }
    65. }

    It's not particularly laggy. I get 20-30fps in the editor during this case. I upped the solver iteration count but that doesn't appear to affect it. It's not like "some" enemies get hit but not other- zero triggers are fired.
    Profiler doesn't really show anything outstanding.

    No errors or warnings. Safety checks are on.

    The enemy:
    upload_2022-6-29_15-48-54.png
    The Bullet:
    upload_2022-6-29_15-49-14.png

    The job itself is running but taking very minimal amount of time, as if no events found in the physics system:
    upload_2022-6-29_16-4-44.png
     
    Last edited: Jun 30, 2022
  2. Reticulatas

    Reticulatas

    Joined:
    Jul 31, 2012
    Posts:
    25
    Interestingly, if I make a build the game instantly crashes when I touch an enemy.


    Code (csharp):
    1.  
    2. ========== OUTPUTTING STACK TRACE ==================
    3.  
    4. 0x00007FF8EA775A94 (lib_burst_generated) [F:\Projects\KillDoods\Library\PackageCache\com.unity.entities@0.51.0-preview.32\Unity.Entities\EntityCommandBuffer.cs:2507] Unity.Entities.EntityCommandBuffer/EcbWalker`1<Unity.Entities.EntityCommandBuffer/PlaybackProcessor>.1409::Unity.Entities.EntityCommandBuffer.EcbWalker`1<Unity.Entities.EntityCommandBuffer.PlaybackProcessor>.ProcessChain
    5. 0x00007FF8EA771471 (lib_burst_generated) 6cbe9b44f55dff161edecf05c9660a36_avx2
    6. 0x0000026DE2404083 (Mono JIT Code) (wrapper managed-to-native) object:wrapper_native_00007FF8EA88FAA0 (intptr,int,intptr,int,int)
    7. 0x0000026DFB94D40A (Mono JIT Code) (wrapper delegate-invoke) <Module>:invoke_void_intptr_int_intptr_int_int (intptr,int,intptr,int,int)
    8. 0x0000026DFB94D32D (Mono JIT Code) [F:\Projects\KillDoods\Library\PackageCache\com.unity.entities@0.51.0-preview.32\Unity.Entities\ECBInterop.interop.gen.cs:98] Unity.Entities.ECBInterop:_forward_mono_ProcessChainChunk (void*,int,Unity.Entities.ECBChainPlaybackState*,int,int)
    9. 0x0000026DFB94D25B (Mono JIT Code) [F:\Projects\KillDoods\Library\PackageCache\com.unity.entities@0.51.0-preview.32\Unity.Entities\ECBInterop.interop.gen.cs:80] Unity.Entities.ECBInterop:ProcessChainChunk (void*,int,Unity.Entities.ECBChainPlaybackState*,int,int)
    10. 0x0000026DE549FD3B (Mono JIT Code) [F:\Projects\KillDoods\Library\PackageCache\com.unity.entities@0.51.0-preview.32\Unity.Entities\EntityCommandBuffer.cs:2459] Unity.Entities.EntityCommandBuffer/EcbWalker`1<Unity.Entities.EntityCommandBuffer/PlaybackProcessor>:WalkChains (Unity.Entities.EntityCommandBuffer)
    11. 0x0000026DE549F3CB (Mono JIT Code) [F:\Projects\KillDoods\Library\PackageCache\com.unity.entities@0.51.0-preview.32\Unity.Entities\EntityCommandBuffer.cs:2321] Unity.Entities.EntityCommandBuffer:PlaybackInternal (Unity.Entities.EntityDataAccess*)
    12. 0x0000026DE549F0D3 (Mono JIT Code) [F:\Projects\KillDoods\Library\PackageCache\com.unity.entities@0.51.0-preview.32\Unity.Entities\EntityCommandBuffer.cs:2283] Unity.Entities.EntityCommandBuffer:Playback (Unity.Entities.EntityManager)
    13. 0x0000026DE549EBFB (Mono JIT Code) [F:\Projects\KillDoods\Library\PackageCache\com.unity.entities@0.51.0-preview.32\Unity.Entities\EntityCommandBufferSystem.cs:271] Unity.Entities.EntityCommandBufferSystem:FlushPendingBuffers (bool)
    14. 0x0000026DE549EA33 (Mono JIT Code) [F:\Projects\KillDoods\Library\PackageCache\com.unity.entities@0.51.0-preview.32\Unity.Entities\EntityCommandBufferSystem.cs:193] Unity.Entities.EntityCommandBufferSystem:OnUpdate ()
    15. 0x0000026DE549D361 (Mono JIT Code) [F:\Projects\KillDoods\Library\PackageCache\com.unity.entities@0.51.0-preview.32\Unity.Entities\ComponentSystem.cs:115] Unity.Entities.ComponentSystem:Update ()
    16. 0x0000026DE549E66F (Mono JIT Code) [F:\Projects\KillDoods\Library\PackageCache\com.unity.entities@0.51.0-preview.32\Unity.Entities\ComponentSystemGroup.cs:585] Unity.Entities.ComponentSystemGroup:UpdateAllSystems ()
    17. 0x0000026DE549E1C3 (Mono JIT Code) [F:\Projects\KillDoods\Library\PackageCache\com.unity.entities@0.51.0-preview.32\Unity.Entities\ComponentSystemGroup.cs:524] Unity.Entities.ComponentSystemGroup:OnUpdate ()
    18. 0x0000026DE549D361 (Mono JIT Code) [F:\Projects\KillDoods\Library\PackageCache\com.unity.entities@0.51.0-preview.32\Unity.Entities\ComponentSystem.cs:115] Unity.Entities.ComponentSystem:Update ()
    19. 0x0000026DE549D109 (Mono JIT Code) [F:\Projects\KillDoods\Library\PackageCache\com.unity.entities@0.51.0-preview.32\Unity.Entities\ScriptBehaviourUpdateOrder.cs:428] Unity.Entities.ScriptBehaviourUpdateOrder/DummyDelegateWrapper:TriggerUpdate ()
    20. 0x0000026DBEEC6CF0 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
    21. 0x00007FF8D0DFF1E0 (mono-2.0-bdwgc) mono_get_runtime_build_info
    22. 0x00007FF8D0D82AC2 (mono-2.0-bdwgc) mono_perfcounters_init
    23. 0x00007FF8D0D8BB1F (mono-2.0-bdwgc) mono_runtime_invoke
    24. 0x00007FF8BF57031D (UnityPlayer) UnityMain
    25. 0x00007FF8BF56CA9C (UnityPlayer) UnityMain
    26. 0x00007FF8BF12C3FD (UnityPlayer) UnityMain
    27. 0x00007FF8BF12C41F (UnityPlayer) UnityMain
    28. 0x00007FF8BF132542 (UnityPlayer) UnityMain
    29.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF8BEB43FBF)
    30. 0x00007FF8BEB43FBF (UnityPlayer) (function-name not available)
    31.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF8BEB41C3B)
    32. 0x00007FF8BEB41C3B (UnityPlayer) (function-name not available)
    33.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF8BEB47976)
    34. 0x00007FF8BEB47976 (UnityPlayer) (function-name not available)
    35. 0x00007FF8BEB4893B (UnityPlayer) UnityMain
    36.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF72AB411F2)
    37. 0x00007FF72AB411F2 (Kill1Billion) (function-name not available)
    38. 0x00007FF9D1727034 (KERNEL32) BaseThreadInitThunk
    39. 0x00007FF9D24E2651 (ntdll) RtlUserThreadStart
    40.  
     
  3. Reticulatas

    Reticulatas

    Joined:
    Jul 31, 2012
    Posts:
    25
    I have resolved this issue. I'm not sure what the actual problem was but I copied the StatefulTriggerEvent code from the PhysicsSamples and it seems to have fixed this.