-
Notifications
You must be signed in to change notification settings - Fork 817
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[VFX] Add test about mesh deletion while rendering
Initially, I was investigating on UUM-6234 but I can't repro: https://media.github.cds.internal.unity3d.com/user/42/files/af4a29ce-dcfe-41f1-a855-2e4345d5fa36 Not sure what fixes this, it can be relative to - https://github.cds.internal.unity3d.com/unity/unity/pull/15841 : Safer access to Mesh buffer using Inc/Dec RefCount - https://github.cds.internal.unity3d.com/unity/unity/pull/20023: Change culling access, maybe could have been done to early in some cases ?
- Loading branch information
1 parent
e837679
commit a484e13
Showing
10 changed files
with
173 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
Tests/SRPTests/Packages/com.unity.testing.visualeffectgraph/Tests/Editor/VFXComponentTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
using System.Collections; | ||
using System.IO; | ||
using System.Linq; | ||
using UnityEngine.TestTools; | ||
using NUnit.Framework; | ||
using UnityEngine; | ||
using UnityEngine.VFX; | ||
using UnityEditor.VFX; | ||
|
||
namespace UnityEditor.VFX.Test | ||
{ | ||
public class VisualEffectTest : VFXPlayModeTest | ||
{ | ||
[OneTimeSetUp] | ||
public void Init() | ||
{ | ||
VFXTestCommon.CloseAllUnecessaryWindows(); | ||
} | ||
|
||
[OneTimeTearDown] | ||
public void CleanUp() | ||
{ | ||
VFXTestCommon.DeleteAllTemporaryGraph(); | ||
} | ||
|
||
[UnityTest, Description("Regression test UUM-6234")] | ||
public IEnumerator Delete_Mesh_While_Rendering() | ||
{ | ||
yield return new EnterPlayMode(); | ||
|
||
var graph = VFXTestCommon.MakeTemporaryGraph(); | ||
string meshFilePath; | ||
{ | ||
//Create Mesh Asset | ||
Mesh mesh; | ||
{ | ||
var resourceMesh = new Mesh() | ||
{ | ||
vertices = new[] | ||
{ | ||
new Vector3(0, 0, 0), | ||
new Vector3(1, 1, 0), | ||
new Vector3(1, 0, 0), | ||
}, | ||
triangles = new[] {0, 1, 2} | ||
}; | ||
var guid = System.Guid.NewGuid().ToString(); | ||
meshFilePath = string.Format(VFXTestCommon.tempBasePath + "Mesh_{0}.asset", guid); | ||
AssetDatabase.CreateAsset(resourceMesh, meshFilePath); | ||
AssetDatabase.SaveAssets(); | ||
mesh = AssetDatabase.LoadAssetAtPath<Mesh>(meshFilePath); | ||
} | ||
Assert.IsNotNull(mesh); | ||
|
||
//Create VFXAsset | ||
{ | ||
var staticMeshOutput = ScriptableObject.CreateInstance<VFXStaticMeshOutput>(); | ||
var slots = staticMeshOutput.inputSlots.Where(o => o.value is Mesh).ToArray(); | ||
Assert.IsTrue(slots.Any()); | ||
foreach (var slot in slots) | ||
{ | ||
if (slot.value is Mesh) | ||
slot.value = mesh; | ||
} | ||
graph.AddChild(staticMeshOutput); | ||
|
||
var particleOutput = ScriptableObject.CreateInstance<VFXMeshOutput>(); | ||
particleOutput.SetSettingValue("castShadows", true); | ||
slots = particleOutput.inputSlots.Where(o => o.value is Mesh).ToArray(); | ||
Assert.IsTrue(slots.Any()); | ||
foreach (var slot in slots) | ||
{ | ||
if (slot.value is Mesh) | ||
slot.value = mesh; | ||
} | ||
graph.AddChild(particleOutput); | ||
|
||
var contextInitialize = ScriptableObject.CreateInstance<VFXBasicInitialize>(); | ||
contextInitialize.LinkTo(particleOutput); | ||
graph.AddChild(contextInitialize); | ||
|
||
var spawner = ScriptableObject.CreateInstance<VFXBasicSpawner>(); | ||
spawner.LinkTo(contextInitialize); | ||
graph.AddChild(spawner); | ||
|
||
var burst = ScriptableObject.CreateInstance<VFXSpawnerBurst>(); | ||
spawner.AddChild(burst); | ||
burst.inputSlots[0].value = 1.0f; | ||
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(graph)); | ||
} | ||
} | ||
|
||
var cameraTransform = Camera.main.transform; | ||
cameraTransform.localPosition = Vector3.one; | ||
cameraTransform.LookAt(Vector3.zero); | ||
|
||
//Create object and wait to have visible particles | ||
GameObject currentObject = new GameObject("Delete_Mesh_While_Rendered_With_Output", /*typeof(Transform),*/ typeof(VisualEffect)); | ||
var vfx = currentObject.GetComponent<VisualEffect>(); | ||
vfx.visualEffectAsset = graph.visualEffectResource.asset; | ||
int maxFrame = 64; | ||
while (vfx.aliveParticleCount == 0 && maxFrame-- > 0) | ||
yield return null; | ||
Assert.IsTrue(maxFrame > 0); | ||
|
||
//Delete Mesh & Wait a few frame | ||
File.Delete(meshFilePath); | ||
File.Delete(meshFilePath + ".meta"); | ||
for (int i = 0; i < 4; ++i) | ||
yield return null; | ||
AssetDatabase.Refresh(); | ||
for (int i = 0; i < 4; ++i) | ||
yield return null; | ||
|
||
//Check content from VFX | ||
{ | ||
var meshOutput = graph.children.OfType<VFXMeshOutput>().First(); | ||
var meshSlot = meshOutput.inputSlots.First(o => o.property.type == typeof(Mesh)); | ||
|
||
var mesh = meshSlot.value as UnityEngine.Object; | ||
Assert.IsTrue(mesh == null); //Mesh should be deleted at this point... | ||
Assert.IsFalse(ReferenceEquals(mesh, null)); //... but expected missing reference | ||
} | ||
|
||
yield return new ExitPlayMode(); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...PTests/Packages/com.unity.testing.visualeffectgraph/Tests/Editor/VFXComponentTest.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 2 additions & 0 deletions
2
.../VisualEffectGraph_HDRP/Assets/AllTests/Editor/Unity.VisualEffectGraph.EditorTests.asmdef
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters