Skip to content

Commit 3dd76df

Browse files
committed
test(sprite): destroy the working texture in the new sheet helper
CreateSheetOfSize built a Texture2D and never released it, while both sibling helpers a few lines up destroy theirs after encoding. A Texture2D created in an EditMode test is not collected on its own, so the helper leaked one per call for as long as the run lasted. The helper now matches the siblings exactly - same format arguments, same Path.Combine style, same DestroyImmediate placement - which is the point: an inconsistency between three functions doing the same job is what let this one be written without the line.
1 parent ae9f537 commit 3dd76df

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

TestProjects/UnityMCPTests/Assets/Tests/EditMode/Tools/ManageSpriteTests.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,21 @@ private static string CreateNoiseSheet(string name, int side, bool assertOverCei
104104
/// <summary>A flat sheet of an exact pixel size, for grids that do not divide evenly.</summary>
105105
private static string CreateSheetOfSize(string name, int width, int height)
106106
{
107-
var tex = new Texture2D(width, height);
108-
var px = new Color32[width * height];
109-
for (int i = 0; i < px.Length; i++) px[i] = new Color32(255, 0, 0, 255);
110-
tex.SetPixels32(px);
107+
var tex = new Texture2D(width, height, TextureFormat.RGBA32, false);
108+
var pixels = new Color32[width * height];
109+
for (int i = 0; i < pixels.Length; i++)
110+
pixels[i] = new Color32(255, 0, 0, 255);
111+
tex.SetPixels32(pixels);
111112
tex.Apply();
112113

113114
string assetPath = $"{TempRoot}/{name}.png";
114-
System.IO.File.WriteAllBytes(
115-
System.IO.Path.Combine(Directory.GetParent(Application.dataPath).FullName, assetPath),
116-
tex.EncodeToPNG());
115+
string sysPath = Path.Combine(
116+
Directory.GetParent(Application.dataPath).FullName, assetPath);
117+
File.WriteAllBytes(sysPath, tex.EncodeToPNG());
118+
// Both sibling helpers destroy their working texture here; this one did not, and
119+
// a Texture2D built in an EditMode test is not collected on its own.
120+
Object.DestroyImmediate(tex);
121+
117122
AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceSynchronousImport);
118123
return assetPath;
119124
}

0 commit comments

Comments
 (0)