Search Unity

Bug InvalidOperationException: shared component couldn't be removed due to internal state corruption

Discussion in 'Entity Component System' started by Greexonn, Oct 22, 2022.

  1. Greexonn

    Greexonn

    Joined:
    Mar 10, 2020
    Posts:
    19
    From time to tome this occurs when setting shared component filter on entity query:
    InvalidOperationException: shared component couldn't be removed due to internal state corruption
    Unity.Entities.EntityComponentStore.RemoveSharedComponentReference_Unmanaged (System.Int32 sharedComponentIndex, System.Int32 numRefs) (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/EntityComponentStore.cs:1722)
    Unity.Entities.EntityDataAccess.RemoveSharedComponentReference (System.Int32 sharedComponentIndex, System.Int32 numRefs) (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/EntityDataAccess.cs:2024)
    Unity.Entities.EntityQueryImpl._ResetFilter (Unity.Entities.EntityQueryImpl* self) (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/Iterators/EntityQuery.cs:1638)
    Unity.Entities.EntityQueryImpl.ResetFilter (Unity.Entities.EntityQueryImpl* self) (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/Iterators/EntityQuery.interop.gen.cs:88)
    Unity.Entities.EntityQueryImpl.ResetFilter () (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/Iterators/EntityQuery.cs:1673)
    Unity.Entities.EntityQueryImpl.SetSharedComponentFilterUnmanaged[SharedComponent1] (SharedComponent1 sharedComponent1) (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/Iterators/EntityQuery.cs:1665)
    Unity.Entities.EntityQuery.SetSharedComponentFilter[SharedComponent] (SharedComponent sharedComponent) (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/Iterators/EntityQuery.cs:2972)
    ...

    Next time the assertion in the same method gets triggered:
    AssertionException: Assertion failure. Value was False
    Expected: True
    UnityEngine.Assertions.Assert.Fail (System.String message, System.String userMessage) (at /Users/bokken/buildslave/unity/build/Runtime/Export/Assertions/Assert/AssertBase.cs:29)
    UnityEngine.Assertions.Assert.IsTrue (System.Boolean condition, System.String message) (at /Users/bokken/buildslave/unity/build/Runtime/Export/Assertions/Assert/AssertBool.cs:20)
    UnityEngine.Assertions.Assert.IsTrue (System.Boolean condition) (at /Users/bokken/buildslave/unity/build/Runtime/Export/Assertions/Assert/AssertBool.cs:13)
    Unity.Assertions.Assert.IsTrue (System.Boolean condition) (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/Stubs/Unity.Assertions/Assert.cs:24)
    Unity.Entities.EntityComponentStore.RemoveSharedComponentReference_Unmanaged (System.Int32 sharedComponentIndex, System.Int32 numRefs) (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/EntityComponentStore.cs:1682)
    Unity.Entities.EntityDataAccess.RemoveSharedComponentReference (System.Int32 sharedComponentIndex, System.Int32 numRefs) (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/EntityDataAccess.cs:2024)
    Unity.Entities.EntityQueryImpl._ResetFilter (Unity.Entities.EntityQueryImpl* self) (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/Iterators/EntityQuery.cs:1638)
    Unity.Entities.EntityQueryImpl.ResetFilter (Unity.Entities.EntityQueryImpl* self) (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/Iterators/EntityQuery.interop.gen.cs:88)
    Unity.Entities.EntityQueryImpl.ResetFilter () (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/Iterators/EntityQuery.cs:1673)
    Unity.Entities.EntityQueryImpl.Dispose () (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/Iterators/EntityQuery.cs:531)
    Unity.Entities.EntityQuery.Dispose () (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/Iterators/EntityQuery.cs:2188)
    Unity.Entities.SystemState.DisposeQueries (Unity.Collections.LowLevel.Unsafe.UnsafeList`1[Unity.Entities.EntityQuery]& queries) (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/SystemState.cs:382)
    Unity.Entities.SystemState.Dispose () (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/SystemState.cs:348)
    Unity.Entities.WorldUnmanagedImpl.FreeSlotWithoutOnDestroy (System.UInt16 handle, Unity.Entities.SystemState* statePtr) (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/WorldUnmanaged.cs:322)
    Unity.Entities.WorldUnmanagedImpl.FreeSlot (System.UInt16 handle, Unity.Entities.SystemState* statePtr) (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/WorldUnmanaged.cs:351)
    Unity.Entities.WorldUnmanagedImpl.DestroyManagedSystem (Unity.Entities.SystemState* state) (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/WorldUnmanaged.cs:437)
    Unity.Entities.WorldUnmanaged.DestroyManagedSystemState (Unity.Entities.SystemState* state) (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/WorldUnmanaged.cs:1095)
    Unity.Entities.ComponentSystemBase.OnAfterDestroyInternal () (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/ComponentSystemBase.cs:355)
    Unity.Entities.World.DestroyAllSystemsAndLogException () (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/World.cs:1025)
    UnityEngine.Debug:LogException(Exception)
    Unity.Debug:LogException(Exception) (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/Stubs/Unity/Debug.cs:19)
    Unity.Entities.World:DestroyAllSystemsAndLogException() (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/World.cs:1035)
    Unity.Entities.World:Dispose() (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/World.cs:303)
    Unity.Entities.World:DisposeAllWorlds() (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/World.cs:329)
    Unity.Entities.DefaultWorldInitialization:DomainUnloadOrPlayModeChangeShutdown() (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/DefaultWorldInitialization.cs:101)
    Unity.Entities.DefaultWorldInitializationProxy:OnDisable() (at Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/DefaultWorldInitializationProxy.cs:29)

    Details:
    • Unity 2022.2.0b12
    • Entities 1.0.0-exp.8
    I'm developing a turn base game and using shared components to query some effects for a hero and stuff. Everything was ok for entities 0.51 but then I upgraded the game to 1.0 and made all my shared components unmanaged. Now I keep getting corrupted behavior and crashes.

    Unfortunately I can't provide any reproduction steps, cause it's very random.

    Also I've experienced editor crashes setting unmanaged shared components. A crash can occur with or without burst enabled.
     
  2. Greexonn

    Greexonn

    Joined:
    Mar 10, 2020
    Posts:
    19
    Ok, now I can confirm that this problem occurs with Managed versions as well.

    Strange part is I was only able to catch it on intel mac now, no "luck" on m1
     
  3. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    If you've upgraded, but haven't cleared Library folder / not reimported all, I'd highly suggest to do so.

    I've had similar random memory corruption issue in prior Entities releases on absolutely random devices.
    Clean reimport fixed that.

    No idea what was causing it though.
     
  4. Greexonn

    Greexonn

    Joined:
    Mar 10, 2020
    Posts:
    19
    Thank you for the suggestion, but no luck, unfortunately. Deleted Library, but still getting the assertion triggered.

    Even got a crash:
    #0 0x000003ea859848 in Unity.Entities.EntityComponentStore:InsertSharedComponent_Unmanaged (Unity.Entities.TypeIndex,int,void*,void*) [{0x3a79dda00} + 0x240] [/Users/greexonn/Documents/Work/heroic-battles/Library/PackageCache/com.unity.entities@1.0.0-exp.8/Unity.Entities/EntityComponentStore.cs :: 1582u] (0x3ea859608 0x3ea859954) [0x10e4a6a80 - Unity Child Domain]

    #1 0x000003eb11bc30 in Unity.Entities.EntityDataAccess:InsertSharedComponent_Unmanaged<

    Btw, found out not every part of my code works right as well, but still I'd consider this is a valid bug, cause I only use public API's
     
  5. Greexonn

    Greexonn

    Joined:
    Mar 10, 2020
    Posts:
    19
    I've finished getting the project back to 0.51 and testing it. Everything works fine, just as before.

    Hope the fix will arrive soon, cause I've really loved new APIs so far
     
    Last edited: Oct 27, 2022
  6. Greexonn

    Greexonn

    Joined:
    Mar 10, 2020
    Posts:
    19
    Just bumping this up cause this is still the case in 1.0.0-pre.65 and 2022.2.12f1
     
  7. gencontain

    gencontain

    Joined:
    Nov 15, 2012
    Posts:
    15
    Bumping this too, I'm seeing the same "InvalidOperationException: shared component couldn't be removed due to internal state corruption" when setting a shared component filter. Also on 1.0.0-pre.65 and 2022.2.12f1
     
    Greexonn likes this.
  8. gencontain

    gencontain

    Joined:
    Nov 15, 2012
    Posts:
    15
    Confirmed it also happens on 2022.2.14f1. I made a small repro and reported it as IN-37939, seems all it takes is removing a few shared components from entities.
     
    Greexonn likes this.
  9. Greexonn

    Greexonn

    Joined:
    Mar 10, 2020
    Posts:
    19
    Wow, that sounds like the only case I haven't checked trying to make a repro. I'm very grateful)
     
  10. elliotc-unity

    elliotc-unity

    Unity Technologies

    Joined:
    Nov 5, 2015
    Posts:
    230
    I've been looking for a repro for this for months! Thank you for posting the bug number! Unzipping now.
     
    Greexonn likes this.
  11. elliotc-unity

    elliotc-unity

    Unity Technologies

    Joined:
    Nov 5, 2015
    Posts:
    230
    And it happened! Beautiful! Thank you @gencontain !
     
    Occuros and tertle like this.
  12. gencontain

    gencontain

    Joined:
    Nov 15, 2012
    Posts:
    15
    My repro doesn't throw exceptions anymore on Unity 2022.2.21f1 and com.unity.entities 1.0.10, looks like this got fixed.
     
    elliotc-unity likes this.