Search Unity

Random TypeLoadException error when using IJobParallelForBatch

Discussion in 'Entity Component System' started by korzen303, Jul 18, 2018.

  1. korzen303

    korzen303

    Joined:
    Oct 2, 2012
    Posts:
    223
    I am getting the following exceptions when using IJobParallelForBatch in my jobified physics solver.
    I am assuming it is a bug as it is random, happens around 70% of the time.
    The batched job is only calling a native method, but the exceptions get thrown even if I comment out the job body (including its fields)

    Code (CSharp):
    1. TypeLoadException: Recursive type definition detected
    2. Unity.Jobs.JobHandle:ScheduleBatchedJobsAndComplete(JobHandle&)
    3. Unity.Jobs.JobHandle:Complete() (at C:/buildslave/unity/build/Runtime/Jobs/ScriptBindings/JobHandle.bindings.cs:20)
    4. DefKit.SequentialGaussSeidelSolver:SubStepPhysics(Single, Int32, SolverSystem[], JobHandle) (at Assets/DefKit/Core/Dynamics/Solver/SequentialGaussSeidelSolver.cs:315)
    5. DefKit.SequentialGaussSeidelSolver:StepPhysics(Single, Int32) (at Assets/DefKit/Core/Dynamics/Solver/SequentialGaussSeidelSolver.cs:180)
    6. DefKit.SequentialGaussSeidelSolver:Update() (at Assets/DefKit/Core/Dynamics/Solver/SequentialGaussSeidelSolver.cs:79)
     
  2. vanxining

    vanxining

    Joined:
    Mar 29, 2018
    Posts:
    20
    The same problem. Can anybody explain this error?
    Thanks!
     
  3. Bytestorm83

    Bytestorm83

    Joined:
    Mar 17, 2018
    Posts:
    5
    For some reason that I cannot fathom at this time, IJobParallelForBatch does not allow for multiple similar type declarations at the job level.

    This means that we cannot have, for example, two different ints declared, even as readonly, at the same type.

    That was what caused the issue for me when I encountered this error.

    It even happens across Native Containers! I cannot have a NativeArray, and a NativeHashMap have a struct declared at the same time.

    It is permissible, however, to have a struct declared, that has multiple similar declarations.

    EDIT:: Oddly, after updating to 2018.2.2f1, I stopped encountering this error. Maybe I just needed to restart Unity, or maybe there was an actual problem.
     
    Last edited: Aug 5, 2018
  4. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    883
    Same problem here.
    jobs 0.0.7-preview-6
     
  5. Deleted User

    Deleted User

    Guest

    This seems to happen for me if the job is running when my scripts reload. Since the exception seems to break the job, that means my jobs work every other C# compile.
     
  6. Orimay

    Orimay

    Joined:
    Nov 16, 2012
    Posts:
    304
    Same issue with Jobs preview - 0.1.1
     
  7. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Does anyone have a small project folder that clearly produces the issue?
     
  8. Orimay

    Orimay

    Joined:
    Nov 16, 2012
    Posts:
    304
    It seems like there are some race conditions since sometimes everything works just fine
    Code (CSharp):
    1. TypeLoadException: Recursive type definition detected
    2. Unity.Jobs.JobHandle:ScheduleBatchedJobsAndComplete(JobHandle&)
    3. Unity.Jobs.JobHandle:Complete()
    4. Unity.Entities.ComponentJobSafetyManager:CompleteAllJobsAndInvalidateArrays() (at Library/PackageCache/com.unity.entities@0.1.1-preview/Unity.Entities/ComponentJobManager.cs:140)
    5. Unity.Entities.EntityManager:CompleteAllJobs() (at Library/PackageCache/com.unity.entities@0.1.1-preview/Unity.Entities/EntityManagerSync.cs:19)
    6. Unity.Entities.EntityManager:BeforeStructuralChange() (at Library/PackageCache/com.unity.entities@0.1.1-preview/Unity.Entities/EntityManagerSync.cs:41)
    7. Unity.Entities.EntityManager:AddComponent(UnsafeMatchingArchetypePtrList, EntityQueryFilter, ComponentType) (at Library/PackageCache/com.unity.entities@0.1.1-preview/Unity.Entities/EntityManagerChangeArchetype.cs:715)
    8. Unity.Entities.EntityManager:AddComponent(EntityQuery, ComponentType) (at Library/PackageCache/com.unity.entities@0.1.1-preview/Unity.Entities/EntityManagerChangeArchetype.cs:84)
    9. Unity.Transforms.ParentSystem:UpdateNewParents() (at Library/PackageCache/com.unity.entities@0.1.1-preview/Unity.Transforms/ParentSystem.cs:231)
    10. Unity.Transforms.ParentSystem:OnUpdate(JobHandle) (at Library/PackageCache/com.unity.entities@0.1.1-preview/Unity.Transforms/ParentSystem.cs:373)
    11. Unity.Entities.JobComponentSystem:InternalUpdate() (at Library/PackageCache/com.unity.entities@0.1.1-preview/Unity.Entities/ComponentSystem.cs:924)
    12. Unity.Entities.ComponentSystemBase:Update() (at Library/PackageCache/com.unity.entities@0.1.1-preview/Unity.Entities/ComponentSystem.cs:284)
    13. Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.entities@0.1.1-preview/Unity.Entities/ComponentSystemGroup.cs:602)
    14. Unity.Entities.ComponentSystem:InternalUpdate() (at Library/PackageCache/com.unity.entities@0.1.1-preview/Unity.Entities/ComponentSystem.cs:800)
    15. Unity.Entities.ComponentSystemBase:Update() (at Library/PackageCache/com.unity.entities@0.1.1-preview/Unity.Entities/ComponentSystem.cs:284)
    16. Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.entities@0.1.1-preview/Unity.Entities/ComponentSystemGroup.cs:602)
    17. Unity.Entities.ComponentSystem:InternalUpdate() (at Library/PackageCache/com.unity.entities@0.1.1-preview/Unity.Entities/ComponentSystem.cs:800)
    18. Unity.Entities.ComponentSystemBase:Update() (at Library/PackageCache/com.unity.entities@0.1.1-preview/Unity.Entities/ComponentSystem.cs:284)
    19. Unity.Entities.DummyDelegateWrapper:TriggerUpdate() (at Library/PackageCache/com.unity.entities@0.1.1-preview/Unity.Entities/ScriptBehaviourUpdateOrder.cs:144)
    And then gets followed by
    Code (CSharp):
    1. IndexOutOfRangeException: Index 7077988 is out of range of '10' Length.
    2. Unity.Collections.NativeArray`1[T].FailOutOfRangeError (System.Int32 index) (at <86888d7bf865490ca0c08194bf6338db>:0)
    3. Unity.Collections.NativeArray`1[T].CheckElementReadAccess (System.Int32 index) (at <86888d7bf865490ca0c08194bf6338db>:0)
    4. Unity.Collections.NativeArray`1[T].get_Item (System.Int32 index) (at <86888d7bf865490ca0c08194bf6338db>:0)
    5. Unity.Physics.BoundingVolumeHierarchy.Refit (Unity.Collections.NativeArray`1[T] aabbs, System.Int32 nodeStartIndex, System.Int32 nodeEndIndex) (at Library/PackageCache/com.unity.physics@0.2.0-preview/Unity.Physics/Collision/Geometry/BoundingVolumeHierarchyBuilder.cs:564)
    6. Unity.Physics.BoundingVolumeHierarchy+FinalizeTreeJob.Execute () (at Library/PackageCache/com.unity.physics@0.2.0-preview/Unity.Physics/Collision/Geometry/BoundingVolumeHierarchyBuilder.cs:842)
    7. Unity.Jobs.IJobExtensions+JobStruct`1[T].Execute (T& data, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at <86888d7bf865490ca0c08194bf6338db>:0)
    8.  
    I am not sure if it will remain if I cut some fragments of my project. Besides, since it doesn't appear all the time, it may be really hard to catch. Hope the stack traces will help the investigation. Also, there's a bunch of "TypeLoadException: Recursive type definition detected" with no stack trace nor any other details at all.
     
  9. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    If someone has a specific Project folder that can be shared in a bug report where this reproduces reasonably commonly with some specific steps, that would be greatly appreciated.
     
  10. Orimay

    Orimay

    Joined:
    Nov 16, 2012
    Posts:
    304
    I just sent the report with the title "Recursive type definition detected"
     
  11. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    What is the case number?
     
  12. Orimay

    Orimay

    Joined:
    Nov 16, 2012
    Posts:
    304
    It's 1180844
     
  13. Farzi

    Farzi

    Joined:
    Nov 29, 2018
    Posts:
    2
    Is there an update on this issue? I'm still seeing it every few builds.
     
  14. Sibz9000

    Sibz9000

    Joined:
    Feb 24, 2018
    Posts:
    149