From cc29e97fa30cdcbd12ff1b060419f8e2bf6711a5 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 7 Oct 2021 09:29:50 +0200 Subject: [PATCH] Fix automatic properties serialization bug --- .../Bindings/BindingsGenerator.Cpp.cs | 17 +++++++++++++++-- Source/Tools/Flax.Build/Bindings/TypeInfo.cs | 5 +++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs index 5daebbeb1..9569c15c5 100644 --- a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs +++ b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs @@ -1323,8 +1323,21 @@ namespace Flax.Build.Bindings if (GenerateCppAutoSerializationSkip(buildData, typeInfo, propertyInfo, propertyInfo.Type)) continue; - var typeHint = GenerateCppAutoSerializationDefineType(buildData, contents, moduleInfo, typeInfo, propertyInfo.Type, propertyInfo); - contents.Append($" SERIALIZE{typeHint}_MEMBER({propertyInfo.Name}, {propertyInfo.Getter.Name}());").AppendLine(); + contents.Append(" {"); + contents.Append(" const auto"); + if (propertyInfo.Getter.ReturnType.IsConstRef) + contents.Append('&'); + contents.Append($" value = {propertyInfo.Getter.Name}();"); + contents.Append(" if (other) { const auto"); + if (propertyInfo.Getter.ReturnType.IsConstRef) + contents.Append('&'); + contents.Append($" otherValue = other->{propertyInfo.Getter.Name}();"); + contents.Append(" if (Serialization::ShouldSerialize(value, &otherValue)) { "); + contents.Append($"stream.JKEY(\"{propertyInfo.Name}\"); Serialization::Serialize(stream, value, &otherValue);"); + contents.Append(" } } else if (Serialization::ShouldSerialize(value, nullptr)) { "); + contents.Append($"stream.JKEY(\"{propertyInfo.Name}\"); Serialization::Serialize(stream, value, nullptr);"); + contents.Append(" }"); + contents.Append('}').AppendLine(); CppAutoSerializeProperties.Add(propertyInfo); } } diff --git a/Source/Tools/Flax.Build/Bindings/TypeInfo.cs b/Source/Tools/Flax.Build/Bindings/TypeInfo.cs index bfead9218..350015507 100644 --- a/Source/Tools/Flax.Build/Bindings/TypeInfo.cs +++ b/Source/Tools/Flax.Build/Bindings/TypeInfo.cs @@ -28,6 +28,11 @@ namespace Flax.Build.Bindings /// public bool IsVoid => Type == "void" && !IsPtr; + /// + /// Gets a value indicating whether this type is constant reference to a value. + /// + public bool IsConstRef => IsRef && IsConst; + /// /// Gets a value indicating whether this type is POD (plain old data). ///