{"record":{"id":"22a804f9e1507e15","repo":"stride3d/stride","slug":"sorting-not-implemented-for-multiple-vertex-buffers-by","errorCode":null,"errorMessage":"Sorting not implemented for multiple vertex buffers by submeshdata","messagePattern":"Sorting not implemented for multiple vertex buffers by submeshdata","errorType":"exception","errorClass":"NotImplementedException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Rendering/Extensions/PolySortExtensions.cs","lineNumber":25,"sourceCode":"using Stride.Core.Mathematics;\nusing Stride.Graphics;\nusing Stride.Graphics.Data;\nusing Stride.Rendering;\n\nnamespace Stride.Extensions\n{\n    public static class PolySortExtensions\n    {\n        public static unsafe void SortMeshPolygons(this MeshDraw meshData, Vector3 viewDirectionForSorting)\n        {\n            // need to have alreade an vertex buffer\n            if (meshData.VertexBuffers == null)\n                throw new ArgumentException();\n            // For now, require a MeshData with an index buffer\n            if (meshData.IndexBuffer == null)\n                throw new NotImplementedException(\"The mesh Data needs to have index buffer\");\n            if (meshData.VertexBuffers.Length != 1)\n                throw new NotImplementedException(\"Sorting not implemented for multiple vertex buffers by submeshdata\");\n\n            if (viewDirectionForSorting == Vector3.Zero)\n            {\n                // By default to -Z if sorting is set to null\n                viewDirectionForSorting = -Vector3.UnitZ;\n            }\n\n            const uint PolySize = 3; // currently only triangle list are supported\n            var polyIndicesSize = PolySize * sizeof(int);\n            var vertexBuffer = meshData.VertexBuffers[0];\n            var oldIndexBuffer = meshData.IndexBuffer;\n            var vertexStride = vertexBuffer.Declaration.VertexStride;\n\n            // Generate the sort list\n            var sortList = new List<KeyValuePair<int, Vector3>>();\n\n            fixed (byte* vertexBufferPointerStart = &vertexBuffer.Buffer.GetSerializationData().Content[vertexBuffer.Offset])\n            fixed (byte* indexBufferPointerStart = &oldIndexBuffer.Buffer.GetSerializationData().Content[oldIndexBuffer.Offset])","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Rendering/Extensions/PolySortExtensions.cs#L7-L43","documentation":"SortMeshPolygons only operates on meshes with exactly one vertex buffer; its polygon-sorting code is not implemented for multiple vertex buffers. This NotImplementedException is thrown when meshData.VertexBuffers.Length != 1.","triggerScenarios":"Calling SortMeshPolygons on a MeshDraw with 2+ VertexBuffers (e.g. separate position and attribute buffers, or multiple streams).","commonSituations":"Meshes using multi-stream vertex layouts; meshes from importers that split position data from attribute data; merging workflows that produced multi-buffer meshes.","solutions":["Re-interleave the mesh into a single vertex buffer before sorting","Exclude multi-buffer meshes from polygon sorting","Prefer GenerateTangentBinormal-style single-buffer meshes (IsSimple) in the pipeline feeding SortMeshPolygons"],"exampleFix":"// before\nsort.SortMeshPolygons(multiStreamMesh, viewDir); // 2 vertex buffers\n// after\nvar single = InterleaveVertexBuffers(multiStreamMesh);\nsort.SortMeshPolygons(single, viewDir);","handlingStrategy":"validation","validationCode":"if (mesh.VertexBuffers == null || mesh.VertexBuffers.Length != 1)\n    mesh = InterleaveToSingleVertexBuffer(mesh);","typeGuard":"static bool IsSingleBuffer(MeshDraw mesh) =>\n    mesh.VertexBuffers != null && mesh.VertexBuffers.Length == 1;","tryCatchPattern":"try { mesh.SortMeshPolygons(viewDir); }\ncatch (NotImplementedException) { /* re-interleave to one buffer or skip */ }","preventionTips":["Avoid multi-stream vertex layouts for meshes that need post-processing passes","Re-interleave after any merge that yields multiple buffers","Prefer IsSimple meshes throughout the geometry pipeline"],"tags":["csharp","rendering","vertex-buffers"],"backgroundTag":"method-not-implemented","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}