Skip to content

Commit 3af6e09

Browse files
gabrieldelacruzEvergreen
authored andcommitted
[VFX] Fix editor crash when deleting textures that are used for rendering in VFX
In some scenarios, it was possible to crash the editor if textures, models or graphics buffers were deleted when an active VFX was using them. Not all the ways to destroy these objects will cause a crash, it depends on the path taken. For instance, deleting texture using "Del" key would work fine, but deleting it using right click + "Delete" would crash. This was due to a cached pointer, used for optimization, that was not invalidated. In VFX there are 3 different command lists, 1 running during update (safe, because it is when the pointers are cached). And 2 running during the rendering. If some object is deleted between VFX manager update and rendering, it would cause the crash. The solution was to keep track of which effects need to reload the objects cache and do that during the first rendering command list (PerCamera). On top of that, we removed some unused values from output update that made the crash more likely to happen with 6 way lighting.
1 parent aeb0eaf commit 3af6e09

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

Packages/com.unity.visualeffectgraph/Editor/Models/Contexts/VFXOutputUpdate.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public override VFXExpressionMapper GetExpressionMapper(VFXDeviceTarget target)
105105

106106
if (target == VFXDeviceTarget.GPU)
107107
{
108-
var expressionMapper = m_Output.GetExpressionMapper(target);
108+
var expressionMapper = VFXExpressionMapper.FromBlocks(m_Output.activeFlattenedChildrenWithImplicit);
109109

110110
var exp = GetExpressionsFromSlots(m_Output);
111111

@@ -126,9 +126,7 @@ public override VFXExpressionMapper GetExpressionMapper(VFXDeviceTarget target)
126126

127127
if (HasFeature(Features.MotionVector))
128128
{
129-
var currentFrameIndex = expressionMapper.FromNameAndId("currentFrameIndex", -1);
130-
if (currentFrameIndex == null)
131-
Debug.LogError("CurrentFrameIndex isn't reachable in encapsulatedOutput for motionVector");
129+
expressionMapper.AddExpression(VFXBuiltInExpression.FrameIndex, "currentFrameIndex", -1);
132130
}
133131

134132
var localSpace = ((VFXDataParticle)GetData()).space == VFXSpace.Local;

0 commit comments

Comments
 (0)