|
1 |
| -using NUnit.Framework; |
| 1 | +using NUnit.Framework; |
2 | 2 | using UnityEngine;
|
3 | 3 | using UnityEngine.TestTools;
|
4 | 4 | using Unity.Graphics.Tests;
|
|
7 | 7 | using UnityEditor.SceneManagement;
|
8 | 8 | using UnityEngine.Rendering;
|
9 | 9 | using Object = UnityEngine.Object;
|
| 10 | +using System; |
10 | 11 |
|
11 | 12 | namespace UnityEditor.Previews
|
12 | 13 | {
|
@@ -104,6 +105,52 @@ public IEnumerator CreatePreviewDoesNotLeakMemoryInWorkers()
|
104 | 105 | }
|
105 | 106 | }
|
106 | 107 |
|
| 108 | + // Test case for UUM-63257 |
| 109 | + [UnityTest] |
| 110 | + public IEnumerator CreateMeshPreviewDoesNotLeakMemoryInWorkers() |
| 111 | + { |
| 112 | + var logEntryString = "There are remaining Allocations on the JobTempAlloc."; |
| 113 | + int prevLogEntryCount = GetLogEntryCount(logEntryString); |
| 114 | + |
| 115 | + var folderName = "Create_Mesh_Preview_Test"; |
| 116 | + try |
| 117 | + { |
| 118 | + AssetDatabase.CreateFolder("Assets", folderName); |
| 119 | + |
| 120 | + for (int i = 0; i < 2; ++i) |
| 121 | + { |
| 122 | + var meshPath = Path.Combine($"Assets/{folderName}", $"m{i}.mesh"); |
| 123 | + var mesh = CreateUniqueMiniMesh(); |
| 124 | + AssetDatabase.CreateAsset(mesh, meshPath); |
| 125 | + yield return new WaitForPreview(mesh, 90.0f); |
| 126 | + } |
| 127 | + |
| 128 | + //Here we catch any unexpected memory leak messages |
| 129 | + int logEntryCountAfterTest = GetLogEntryCount(logEntryString); |
| 130 | + Assert.AreEqual(prevLogEntryCount, logEntryCountAfterTest, "There were leaks in the test"); |
| 131 | + } |
| 132 | + finally |
| 133 | + { |
| 134 | + AssetDatabase.DeleteAsset($"Assets/{folderName}"); |
| 135 | + } |
| 136 | + } |
| 137 | + |
| 138 | + Mesh CreateUniqueMiniMesh() |
| 139 | + { |
| 140 | + // Use random value because the preview won't be regenerated if the mesh is already present in the library cache |
| 141 | + float randomValue = (float)new System.Random(Guid.NewGuid().GetHashCode()).NextDouble(); |
| 142 | + |
| 143 | + Mesh mesh = new Mesh(); |
| 144 | + mesh.vertices = new Vector3[] |
| 145 | + { |
| 146 | + new Vector3(randomValue, 0, 0), |
| 147 | + new Vector3(3.0f, 0, 0), |
| 148 | + new Vector3(0, 1.0f, 0) |
| 149 | + }; |
| 150 | + |
| 151 | + return mesh; |
| 152 | + } |
| 153 | + |
107 | 154 |
|
108 | 155 | [UnityTest]
|
109 | 156 | public IEnumerator AssetPreviewIsCorrect()
|
|
0 commit comments