Skip to content

Commit 273b6e3

Browse files
Dont remove suboutputs objects if it cannot be deserialized (#205)
* Dont remove suboutputs objects if it cannot be deserialized * Update changelog
1 parent 1f5b0fb commit 273b6e3

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

com.unity.visualeffectgraph/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1919
- Fix various bugs in Position (Cone) block [Case 1111053](https://issuetracker.unity3d.com/product/unity/issues/guid/1111053/)
2020
- Fix space issues with blocks and operators taking a camera as input
2121
- Generated shaderName are now consistent with displayed system names
22+
- Don't lose SRP output specific data when SRP package is not present
2223

2324
## [8.0.1] - 2020-02-25
2425

com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXAbstractRenderedOutput.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,9 @@ private void SanitizeSubOutputs()
113113
return;
114114
}
115115

116-
// TODO Uncommenting this code will removed SRP data that are unknown, this is probably not what we want
117-
//int nbRemoved = 0;
118-
//if ((nbRemoved = m_SubOutputs.RemoveAll(s => s == null)) > 0)
119-
// Debug.LogWarningFormat("Remove {0} SRP Sub Outputs that could not be deserialized from {1} of type {2}", nbRemoved, name, GetType());
116+
// Reference equals because we only need to remove actual null sub-output, not the ones that cannot be deserialized
117+
// Because we want to keep reference to unknown SRP outputs. No log because this is internal clean up
118+
m_SubOutputs.RemoveAll(s => object.ReferenceEquals(s, null));
120119

121120
var subOutputsTypes = new HashSet<Type>(); // TODO For some reason constructor that takes a capacity does not exist
122121
for (int i = 0; i < m_SubOutputs.Count; ++i)
@@ -140,11 +139,7 @@ public override void CollectDependencies(HashSet<ScriptableObject> objs, bool ow
140139
{
141140
base.CollectDependencies(objs, ownedOnly);
142141
foreach (var data in m_SubOutputs)
143-
if (data != null)
144-
{
145-
objs.Add(data);
146-
data.CollectDependencies(objs, ownedOnly);
147-
}
142+
objs.Add(data);
148143
}
149144

150145
public override VFXSetting GetSetting(string name)

com.unity.visualeffectgraph/Editor/Models/Contexts/VFXSRPSubOutput.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using UnityEngine;
45
using static UnityEditor.VFX.VFXAbstractRenderedOutput;
56

67
namespace UnityEditor.VFX
@@ -24,6 +25,9 @@ public void Init(VFXAbstractRenderedOutput owner)
2425
public virtual bool supportsExposure { get { return false; } }
2526
public virtual bool supportsMotionVector { get { return false; } }
2627

28+
// Sealed override as SRP suboutputs cannot have dependencies
29+
public sealed override void CollectDependencies(HashSet<ScriptableObject> objs, bool ownedOnly = true) {}
30+
2731
public virtual string GetBlendModeStr()
2832
{
2933
switch (owner.blendMode)

com.unity.visualeffectgraph/Editor/Models/VFXGraph.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,11 @@ public object Backup()
277277
dependencies.Add(this);
278278
CollectDependencies(dependencies);
279279

280-
var result = VFXMemorySerializer.StoreObjectsToByteArray(dependencies.Cast<ScriptableObject>().ToArray(), CompressionLevel.Fastest);
280+
// This is a guard where dependencies that couldnt be deserialized (because script is missing for instance) are removed from the list
281+
// because else StoreObjectsToByteArray is crashing
282+
// TODO Fix that
283+
var safeDependencies = dependencies.Where(o => o != null);
284+
var result = VFXMemorySerializer.StoreObjectsToByteArray(safeDependencies.ToArray(), CompressionLevel.Fastest);
281285

282286
Profiler.EndSample();
283287

0 commit comments

Comments
 (0)