Cache managed serializers for networking replication to prevent from being collected by GC

This commit is contained in:
Wojciech Figat
2022-12-29 14:01:01 +01:00
committed by Wojtek Figat
parent c6bbfdc7f0
commit 1d47374758

View File

@@ -51,13 +51,6 @@ namespace FlaxEngine.Networking
/// <param name="deserialize">Function to call for value deserialization.</param>
[Unmanaged]
public static void AddSerializer(Type type, SerializeFunc serialize, SerializeFunc deserialize)
{
// C#-only types (eg. custom C# structures) cannot use native serializers due to missing ScriptingType
if (typeof(FlaxEngine.Object).IsAssignableFrom(type))
{
Internal_AddSerializer(type, Marshal.GetFunctionPointerForDelegate(serialize), Marshal.GetFunctionPointerForDelegate(deserialize));
}
else
{
if (_managedSerializers == null)
{
@@ -67,6 +60,11 @@ namespace FlaxEngine.Networking
#endif
}
_managedSerializers[type] = new KeyValuePair<SerializeFunc, SerializeFunc>(serialize, deserialize);
// C#-only types (eg. custom C# structures) cannot use native serializers due to missing ScriptingType
if (typeof(FlaxEngine.Object).IsAssignableFrom(type))
{
Internal_AddSerializer(type, Marshal.GetFunctionPointerForDelegate(serialize), Marshal.GetFunctionPointerForDelegate(deserialize));
}
}