refactor: optimize memory for mega-meshes and fix collection usage

- Switch large/dynamic collections from StackScope to Allocator.Temp/Persistent to prevent stack overflow
- Remove redundant Resize calls; use capacity in constructor + Add or AsSpan().Fill for initialization
- Correctly propagate Allocator parameter for returned collections
- Ensure all temporary collections are properly disposed before returning
- Refine ClodBuilder, ClodPartition, ClodBoundsHelper, and ClodSimplify for high-scale mesh processing
This commit is contained in:
2026-03-17 02:34:42 +00:00
parent 22fdae1061
commit 0a3502b858
4 changed files with 45 additions and 36 deletions

View File

@@ -20,8 +20,8 @@ internal static class ClodSimplify
return indices;
}
using var scope = AllocationManager.CreateStackScope();
var lod = new UnsafeList<uint>(indices.Length, scope.AllocationHandle);
// Use Allocator.Temp for LOD results to avoid stack overflow on mega-meshes
var lod = new UnsafeList<uint>((nuint)indices.Length, Allocator.Temp);
lod.Resize((nuint)indices.Length);
uint options = MeshOptApi.SimplifySparse | MeshOptApi.SimplifyErrorAbsolute;
@@ -124,7 +124,6 @@ internal static class ClodSimplify
float* error
)
{
// Simplified version - deindex and use sloppy simplification
// Implementation details would involve creating a subset for sparse simplification
// Placeholder for sloppy simplification fallback logic
}
}