Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Bug SpriteShapeController : InvalidOperationException

Discussion in '2D' started by castor76, Jul 6, 2021.

  1. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    If you call BakeMesh();

    and then have scene unloaded so the SpriteShapeController is destroyed I get :

    InvalidOperationException: The previously scheduled job SpriteShapeGenerator writes to the Unity.Collections.NativeArray`1[Unity.Mathematics.float2] SpriteShapeGenerator.m_ColliderPoints. You must call JobHandle.Complete() on the job SpriteShapeGenerator, before you can deallocate the Unity.Collections.NativeArray`1[Unity.Mathematics.float2] safely.
    Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckDeallocateAndThrow (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle handle) (at <adfa4b62400849189388df71c9e26e89>:0)
    Unity.Collections.LowLevel.Unsafe.DisposeSentinel.Dispose (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle& safety, Unity.Collections.LowLevel.Unsafe.DisposeSentinel& sentinel) (at <adfa4b62400849189388df71c9e26e89>:0)
    Unity.Collections.NativeArray`1[T].Dispose () (at <adfa4b62400849189388df71c9e26e89>:0)
    UnityEngine.U2D.SpriteShapeController.DisposeInternal () (at Library/PackageCache/com.unity.2d.spriteshape@6.0.1/Runtime/SpriteShapeController.cs:247)
    UnityEngine.U2D.SpriteShapeController.OnDisable () (at Library/PackageCache/com.unity.2d.spriteshape@6.0.1/Runtime/SpriteShapeController.cs:267)

    Any Idea?
     
  2. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    644
    SpriteShape generator runs in a Job. If BakeMesh is called, please make sure to complete this Job before destroying the Object or Unload the scene.

    var jobHandle = spriteShapeController.BakeMesh();
    jobHandle.Complete();

    Otherwise the Job might be running in parallel while the GameObject is being destroyed, hence the error message. Thanks.