DeserializeSharedComponents hashcode problem

I’m running into assertion errors when trying to deserialize my world.

I have two different types of shared component data that can both have values of 0,0. One is an ID struct, the other is a Sector struct. Due to the way the deserializer is written, when it creates hash codes for these they both equal 0. This causes the deserialization to bomb out due to an assertion failure.

public static unsafe int DeserializeSharedComponents(EntityManager entityManager, BinaryReader reader)
{
    int storedVersion = reader.ReadInt();
    if (storedVersion != CurrentFileFormatVersion)
    {
        throw new ArgumentException(
            $"Attempting to read a entity scene stored in an old file format version (stored version : {storedVersion}, current version : {CurrentFileFormatVersion})");
    }

    int numSharedComponents = reader.ReadInt();

    for (int i = 0; i < numSharedComponents; ++i)
    {
        SharedComponentRecord record = new SharedComponentRecord();
        reader.ReadBytes(&record, sizeof(SharedComponentRecord));

        var buffer = new byte[record.ComponentSize];
        reader.ReadBytes(UnsafeUtility.AddressOf(ref buffer[0]), record.ComponentSize);

        var typeIndex = TypeManager.GetTypeIndexFromStableTypeHash(record.StableTypeHash);
        var data = TypeManager.ConstructComponentFromBuffer(typeIndex, UnsafeUtility.AddressOf(ref buffer[0]));

        // TODO: this recalculation should be removed once we merge the NET_DOTS and non NET_DOTS hashcode calculations
        var hashCode = TypeManager.GetHashCode(data, typeIndex); // record.hashCode;
        int index = entityManager.ManagedComponentStore.InsertSharedComponentAssumeNonDefault(typeIndex, hashCode, data);
        Assert.AreEqual(i + 1, index);
    }

    return numSharedComponents;
}

I can’t write custom HashCode functions for the different component types to offset their values because it calls an internal GetHashCode function.

Has this been changed in the upcoming release?

Looks like it isn’t entities with similar hash codes causing the problem. I removed the other shared component type with 0 for values and it didn’t fix the problem.

Digging deeper into the code it looks like the TypeInfo saved for my blittable SCD always has a SizeInChunk of 0. When deserializing the SizeInChunk value is used to reconstruct the SCD, but as it always returns 0, all my SCDs return values of 0 and deserializing fails.

Can you post the actual exception?

5152892--510521--rider64_RQiKSxf2O5.png
This pic shows the SCD going in during serialization. Size of 8 (2 uints)


This shows the TypeInfo retrieved while deserializing the SCD. The SizeInChunk value is used to perform the MemCpy.
The tinfo in the debugger shows IsZeroSized == true and SizeInChunk == 0.

Oh I’ve seen this before but it was ages ago so I can’t exactly remember solution and I’m out atm so can’t check but…

Do you have proxies setup for your shared component datas? -edit- this is only something for
SerializeUtilityHybrid

No, I don’t. I’m guessing I need to describe how to serialize the SCD? Or at least describe how to deserialize, as the serialization seems to be working fine.