{"record":{"id":"a8d464f8a0e1e75e","repo":"stride3d/stride","slug":"the-mesh-data-needs-to-have-index-buffer","errorCode":null,"errorMessage":"The mesh Data needs to have index buffer","messagePattern":"The mesh Data needs to have index buffer","errorType":"exception","errorClass":"NotImplementedException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Rendering/Extensions/PolySortExtensions.cs","lineNumber":23,"sourceCode":"using System.Linq;\nusing Stride.Core;\nusing 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","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Rendering/Extensions/PolySortExtensions.cs#L5-L41","documentation":"SortMeshPolygons sorts a mesh's triangles back-to-front and requires an index buffer to reorder polygons without touching vertex data. This error (NotImplementedException) is thrown when the supplied MeshDraw has no IndexBuffer; indexless triangle-list meshes are not supported by the sorter.","triggerScenarios":"Calling SortMeshPolygons on a MeshDraw whose IndexBuffer property is null (mesh stores vertices without an index list).","commonSituations":"Sorting unindexed procedurally generated meshes; meshes generated by tools that emit raw triangle soups; forgetting to build an index buffer after generating vertex data.","solutions":["Generate an index buffer for the mesh (one index per vertex: 0..Count-1) before sorting","Convert the mesh to an indexed triangle list at import/generation time","Skip polygon sorting for unindexed meshes or sort by rebuilding a triangle soup with a new index buffer"],"exampleFix":"// before\nsort.SortMeshPolygons(mesh, viewDir); // mesh.IndexBuffer == null\n// after\nif (mesh.IndexBuffer == null)\n    mesh.IndexBuffer = BuildIdentityIndexBuffer(mesh.VertexBuffers[0].Count);\nsort.SortMeshPolygons(mesh, viewDir);","handlingStrategy":"validation","validationCode":"if (mesh.IndexBuffer == null)\n    mesh.IndexBuffer = BuildIdentityIndexBuffer(mesh.VertexBuffers[0].Count);","typeGuard":"static bool CanSortPolygons(MeshDraw mesh) =>\n    mesh.IndexBuffer != null && mesh.VertexBuffers != null && mesh.VertexBuffers.Length == 1;","tryCatchPattern":"try { mesh.SortMeshPolygons(viewDir); }\ncatch (NotImplementedException) { /* mesh lacks index buffer: build one or skip sorting */ }","preventionTips":["Always produce indexed meshes from your generators/importers","Check IndexBuffer before invoking polygon sorting on procedural geometry","Treat unindexed meshes as a distinct asset category in your pipeline"],"tags":["csharp","rendering","index-buffer"],"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"}