Przeglądaj źródła

Add null check for BG serialization

SceneCapture destroys the background rather than disabling it. MPS
breaks when trying to serialize non existent BG transform.
habeebweeb 3 lat temu
rodzic
commit
ddada7ef7f

+ 8 - 3
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Serialization/Serializers/ManagerSerializers/EnvironmentManagerSerializer.cs

@@ -18,15 +18,16 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
             writer.Write(manager.CurrentBgAsset);
 
-            TransformDtoSerializer.Serialize(new TransformDTO(GetBgTransform(manager)), writer);
+            var bgTransform = GetBgTransform(manager);
+            var transformDto = bgTransform ? new TransformDTO(bgTransform) : new TransformDTO();
+
+            TransformDtoSerializer.Serialize(transformDto, writer);
         }
 
         public override void Deserialize(EnvironmentManager manager, BinaryReader reader, SceneMetadata metadata)
         {
             _ = reader.ReadVersion();
 
-            var bg = GetBgTransform(manager);
-
             var bgAsset = reader.ReadString();
 
             var transformDto = TransformDtoSerializer.Deserialize(reader, metadata);
@@ -55,6 +56,10 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
             if (!validBg) return;
 
+            var bg = GetBgTransform(manager);
+
+            if (!bg) return;
+
             bg.position = transformDto.Position;
             bg.rotation = transformDto.Rotation;
             bg.localScale = transformDto.LocalScale;