Skip to content

Commit 870c12e

Browse files
[2020.2][VFX] Fix 1300320 - Infinite compilation loop (#3500)
* Some fixes in expression graph compilation * Fix hack + reformat * Add an invalidation cause EnableChanged
1 parent f91d385 commit 870c12e

File tree

8 files changed

+42
-11
lines changed

8 files changed

+42
-11
lines changed

com.unity.visualeffectgraph/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
88
### Fixed
99
- VFXEventBinderBase throwing a null reference exception in runtime
1010
- Unexpected compilation warning in VFXMouseBinder [Case 1313003](https://issuetracker.unity3d.com/product/unity/issues/guid/1313003/)
11+
- Prevent infinite compilation loop [Case 1298466](https://issuetracker.unity3d.com/product/unity/issues/guid/1298466/)
12+
- Remove some useless compilation triggers (modifying not connected or disabled nodes for instance)
1113

1214
## [10.3.1] - 2020-01-26
1315

com.unity.visualeffectgraph/Editor/GraphView/VFXViewWindow.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,16 @@ void Update()
280280
else
281281
graph.RecompileIfNeeded(true, true);
282282

283+
bool wasDirty = graph.IsExpressionGraphDirty();
284+
283285
controller.RecompileExpressionGraphIfNeeded();
286+
287+
// Hack to avoid infinite recompilation due to UI triggering a recompile TODO: Fix problematic cases that trigger that error
288+
if (!wasDirty && graph.IsExpressionGraphDirty())
289+
{
290+
Debug.LogError("Expression graph was marked as dirty after compiling context for UI. Discard to avoid infinite compilation loop.");
291+
graph.SetExpressionGraphDirty(false);
292+
}
284293
}
285294
}
286295
}

com.unity.visualeffectgraph/Editor/GraphView/Views/Controller/VFXViewControllerExpressions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ public void InvalidateExpressionGraph(VFXModel model, VFXModel.InvalidationCause
4545
{
4646
if (cause != VFXModel.InvalidationCause.kStructureChanged &&
4747
cause != VFXModel.InvalidationCause.kExpressionInvalidated &&
48-
cause != VFXModel.InvalidationCause.kParamChanged)
48+
cause != VFXModel.InvalidationCause.kParamChanged &&
49+
cause != VFXModel.InvalidationCause.kEnableChanged)
4950
{
5051
ExpressionGraphDirtyParamOnly = false;
5152
return;

com.unity.visualeffectgraph/Editor/Models/Blocks/VFXBlock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public bool enabled
3131
set
3232
{
3333
m_Disabled = !value;
34-
Invalidate(InvalidationCause.kStructureChanged);
34+
Invalidate(InvalidationCause.kEnableChanged);
3535
}
3636
}
3737
public virtual bool isValid

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,28 @@ protected override void OnInvalidate(VFXModel model, InvalidationCause cause)
167167
if (cause == InvalidationCause.kStructureChanged ||
168168
cause == InvalidationCause.kConnectionChanged ||
169169
cause == InvalidationCause.kExpressionInvalidated ||
170-
cause == InvalidationCause.kSettingChanged)
170+
cause == InvalidationCause.kSettingChanged ||
171+
cause == InvalidationCause.kEnableChanged)
171172
{
172173
if (hasBeenCompiled || CanBeCompiled())
173-
Invalidate(InvalidationCause.kExpressionGraphChanged);
174+
{
175+
bool skip = false;
176+
177+
// Check if the invalidation comes from a disable block and in that case don't recompile
178+
if (cause != InvalidationCause.kEnableChanged)
179+
{
180+
VFXBlock block = null;
181+
if (model is VFXBlock)
182+
block = (VFXBlock)model;
183+
else if (model is VFXSlot)
184+
block = ((VFXSlot)model).owner as VFXBlock;
185+
186+
skip = block != null && !block.enabled;
187+
}
188+
189+
if (!skip)
190+
Invalidate(InvalidationCause.kExpressionGraphChanged);
191+
}
174192
}
175193
}
176194

com.unity.visualeffectgraph/Editor/Models/Operators/VFXOperator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public override bool ResyncSlots(bool notify)
4141
try
4242
{
4343
changed = base.ResyncSlots(notify);
44-
if (notify)
44+
if (changed && notify)
4545
foreach (var slot in outputSlots) // invalidate expressions on output slots
4646
slot.InvalidateExpressionTree();
4747
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ protected override void OnInvalidate(VFXModel model, VFXModel.InvalidationCause
502502
EditorUtility.SetDirty(this);
503503
}
504504

505-
if (cause == VFXModel.InvalidationCause.kExpressionGraphChanged || cause == VFXModel.InvalidationCause.kConnectionChanged)
505+
if (cause == VFXModel.InvalidationCause.kExpressionGraphChanged)
506506
{
507507
m_ExpressionGraphDirty = true;
508508
m_DependentDirty = true;
@@ -549,10 +549,10 @@ public bool IsExpressionGraphDirty()
549549
return m_ExpressionGraphDirty;
550550
}
551551

552-
public void SetExpressionGraphDirty()
552+
public void SetExpressionGraphDirty(bool dirty = true)
553553
{
554-
m_ExpressionGraphDirty = true;
555-
m_DependentDirty = true;
554+
m_ExpressionGraphDirty = dirty;
555+
m_DependentDirty = dirty;
556556
}
557557

558558
public void SetExpressionValueDirty()
@@ -646,8 +646,8 @@ void RecurseSubgraphRecreateCopy(IEnumerable<VFXModel> children)
646646
else if (child is VFXSubgraphOperator operatorChild)
647647
{
648648
operatorChild.RecreateCopy();
649-
operatorChild.ResyncSlots(true);
650-
operatorChild.UpdateOutputExpressions();
649+
if (operatorChild.ResyncSlots(true))
650+
operatorChild.UpdateOutputExpressions();
651651
}
652652
}
653653
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public enum InvalidationCause
5151
kExpressionGraphChanged,// Expression graph must be recomputed
5252
kUIChanged, // UI stuff has changed
5353
kUIChangedTransient, // UI stuff has been changed be does not require serialization
54+
kEnableChanged, // Node has been enabled/disabled
5455
}
5556

5657
public new virtual string name { get { return string.Empty; } }

0 commit comments

Comments
 (0)