Different SharedComponent get same result by TypeManager.GetHashCode

public struct Test1 : ISharedComponentData {
    public int value;
}

public struct Test2 : ISharedComponentData {
    public int value;
}

public void Print() {
    Test1 x = new Test1 { value = 1 };
    Test2 y = new Test2 { value = 1 };

    Debug.Log(TypeManager.GetHashCode(ref x));
    Debug.Log(TypeManager.GetHashCode(ref y));
}

8727789--1180746--upload_2023-1-13_20-54-32.png

It is a bug ?

When world dispose, and dispose entity queries,if entity query has set this SharedComponents filter, It will cause error :

This seems expected to me. They’re a struct so aren’t compared by ref, instead compared by value.

1 Like

The hash being the same is expected, but the internal state corruption as a result is a bug, which is my own fault. Will fix. (There’s a hash table that uses this hash as a key, and it should actually use this hash + the type index as the key.)

3 Likes

Actually, I thought that was the fix, but now looking at it further I think I was wrong and now I have no idea how you got that exception to throw. @hxhloveunity can you share a bit more about how you did your querying and what the callstack for that exception was?

public struct TestShareComponent1 : ISharedComponentData {
    public int value;
}

public struct TestShareComponent2 : ISharedComponentData {
    public int value;
}


[DisableAutoCreation]
public partial class TestSystem : SystemBase {
    private EntityQuery test1Query;
    private EntityQuery test2Query;

    protected override void OnCreate() {
        test1Query = GetEntityQuery(typeof(TestShareComponent1));
        test2Query = GetEntityQuery(typeof(TestShareComponent2));
    }

    protected override void OnUpdate() {
        test1Query.SetSharedComponentFilter(new TestShareComponent1 {
            value = 1
        });

        test2Query.SetSharedComponentFilter(new TestShareComponent2 {
            value = 1
        });
    }
}

in Entities 1.0.0-pre.15,error still exist when you dispose world

Ah! Thanks! Running that test on master (a bit ahead of pre.47), I don’t see the exception. Could you try again on .47?

We modified the source code of entities, so it’s not easy to upgrade directly. I will come back and give feedback after we upgrade later.

1 Like