Search Unity

Bug InvalidOperationException when cloning a CollisionWorld

Discussion in 'Physics for ECS' started by alfiare, Jan 26, 2023.

  1. alfiare

    alfiare

    Joined:
    Feb 10, 2017
    Posts:
    30
    I'm upgrading to the 1.0 version and I clone the collision world so I can hand it off to a rather long running job that uses it for a bunch of things. I'm trying to do this with the following inside a SystemBase system...

    Code (CSharp):
    1. RefRW<PhysicsWorldSingleton> physicsWorldSingleton = SystemAPI.GetSingletonRW<PhysicsWorldSingleton>();
    2.             _clonedWorld = physicsWorldSingleton.ValueRW.PhysicsWorld.CollisionWorld.Clone();
    But it always throws this error...
    InvalidOperationException: The previously scheduled job Broadphase:prepareStaticBodyDataJob writes to the UNKNOWN_OBJECT_TYPE PrepareStaticBodyDataJob.FiltersOut. You must call JobHandle.Complete() on the job Broadphase:prepareStaticBodyDataJob, before you can read from the UNKNOWN_OBJECT_TYPE safely.
    Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckReadAndThrowNoEarlyOut (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle handle) (at <bdd20210bb844b2e88e1149ea99da5ef>:0)
    Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckReadAndThrow (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle handle) (at <bdd20210bb844b2e88e1149ea99da5ef>:0)
    Unity.Collections.NativeArray`1[T]..ctor (Unity.Collections.NativeArray`1[T] array, Unity.Collections.Allocator allocator) (at <bdd20210bb844b2e88e1149ea99da5ef>:0)
    Unity.Physics.Broadphase+Tree.Clone () (at Library/PackageCache/com.unity.physics@1.0.0-pre.15/Unity.Physics/Collision/World/Broadphase.cs:443)
    Unity.Physics.Broadphase.Clone () (at Library/PackageCache/com.unity.physics@1.0.0-pre.15/Unity.Physics/Collision/World/Broadphase.cs:58)
    Unity.Physics.CollisionWorld.Clone () (at Library/PackageCache/com.unity.physics@1.0.0-pre.15/Unity.Physics/Collision/World/CollisionWorld.cs:118)
    StratheonMin.Client.TypeSystem.Plans.ECS.Systems.ConnectionValidatorSystem.LaunchValidationJob () (at Assets/Assemblies/StratheonMin.Client/TypeSystem/Plans/ECS/Systems/ConnectionValidatorSystem.cs:112)
    StratheonMin.Client.TypeSystem.Plans.ECS.Systems.ConnectionValidatorSystem.InternalOnUpdate (Unity.Jobs.JobHandle inputDeps) (at Assets/Assemblies/StratheonMin.Client/TypeSystem/Plans/ECS/Systems/ConnectionValidatorSystem.cs:83)
    StratheonMin.Client.PlanBuilder.ECS.Systems.ClientConnectionValidatorSystem.InternalOnUpdate (Unity.Jobs.JobHandle inputDeps) (at Assets/Assemblies/StratheonMin.Client/PlanBuilder/ECS/Systems/ClientConnectionValidatorSystem.cs:35)
    StratheonMin.Client.TypeSystem.Plans.ECS.Systems.BasePlanSystem.CallInternalOnOpdate () (at Assets/Assemblies/StratheonMin.Client/TypeSystem/Plans/ECS/Systems/BasePlanSystem.cs:33)
    StratheonMin.Client.TypeSystem.Plans.ECS.Systems.BasePlanSystem.OnUpdate () (at Assets/Assemblies/StratheonMin.Client/TypeSystem/Plans/ECS/Systems/BasePlanSystem.cs:28)
    Unity.Entities.SystemBase.Update () (at Library/PackageCache/com.unity.entities@1.0.0-pre.15/Unity.Entities/SystemBase.cs:428)
    Unity.Entities.ComponentSystemGroup.UpdateAllSystems () (at Library/PackageCache/com.unity.entities@1.0.0-pre.15/Unity.Entities/ComponentSystemGroup.cs:670)
    UnityEngine.Debug:LogException(Exception)
    Unity.Debug:LogException(Exception) (at Library/PackageCache/com.unity.entities@1.0.0-pre.15/Unity.Entities/Stubs/Unity/Debug.cs:19)
    Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at Library/PackageCache/com.unity.entities@1.0.0-pre.15/Unity.Entities/ComponentSystemGroup.cs:675)
    Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.entities@1.0.0-pre.15/Unity.Entities/ComponentSystemGroup.cs:628)
    Unity.Entities.SystemBase:Update() (at Library/PackageCache/com.unity.entities@1.0.0-pre.15/Unity.Entities/SystemBase.cs:416)
    Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at Library/PackageCache/com.unity.entities@1.0.0-pre.15/Unity.Entities/ComponentSystemGroup.cs:670)
    Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.entities@1.0.0-pre.15/Unity.Entities/ComponentSystemGroup.cs:628)
    Unity.Entities.SystemBase:Update() (at Library/PackageCache/com.unity.entities@1.0.0-pre.15/Unity.Entities/SystemBase.cs:416)
    Unity.Entities.DummyDelegateWrapper:TriggerUpdate() (at Library/PackageCache/com.unity.entities@1.0.0-pre.15/Unity.Entities/ScriptBehaviourUpdateOrder.cs:526)


    Am I doing this wrong? I used to use the call to RegisterPhysicsSystemsReadOnly() in the system startup in the previous version but the docs for the current version say that's been removed in favor of the new GetSingletonRW call.
     
  2. JMPM-UNITY

    JMPM-UNITY

    Unity Technologies

    Joined:
    Jun 16, 2021
    Posts:
    93
    Hey @alfiare, I will look into this issue. Thanks for reporting!
     
    alfiare likes this.
  3. alfiare

    alfiare

    Joined:
    Feb 10, 2017
    Posts:
    30
    Hi there, just wondering if there's been any movement on this?
     
  4. JMPM-UNITY

    JMPM-UNITY

    Unity Technologies

    Joined:
    Jun 16, 2021
    Posts:
    93
    From our team: "it sounds like there is a job still running that is using the same data, and thus accessing the singleton component without syncing the job is invalid behavior and the safety system is reporting that. The UNKNOWN_OBJECT bit is part of the safety system when we can't determine the type but the overall recommendation seems correct"