stride3d/stride · error · NotImplementedException
The mesh Data needs to have index buffer
Error message
The mesh Data needs to have index buffer
What it means
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.
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
Example fix
// before
sort.SortMeshPolygons(mesh, viewDir); // mesh.IndexBuffer == null
// after
if (mesh.IndexBuffer == null)
mesh.IndexBuffer = BuildIdentityIndexBuffer(mesh.VertexBuffers[0].Count);
sort.SortMeshPolygons(mesh, viewDir); Defensive patterns
Strategy: validation
Validate before calling
if (mesh.IndexBuffer == null)
mesh.IndexBuffer = BuildIdentityIndexBuffer(mesh.VertexBuffers[0].Count); Type guard
static bool CanSortPolygons(MeshDraw mesh) =>
mesh.IndexBuffer != null && mesh.VertexBuffers != null && mesh.VertexBuffers.Length == 1; Try / catch
try { mesh.SortMeshPolygons(viewDir); }
catch (NotImplementedException) { /* mesh lacks index buffer: build one or skip sorting */ } Prevention
- 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
When it happens
Trigger: Calling SortMeshPolygons on a MeshDraw whose IndexBuffer property is null (mesh stores vertices without an index list).
Common situations: Sorting unindexed procedurally generated meshes; meshes generated by tools that emit raw triangle soups; forgetting to build an index buffer after generating vertex data.
Related errors
- destination length does not match the amount of indices…
- Non-matching vertex buffer declarations.
- Can only merge TriangleList.
- Sorting not implemented for multiple vertex buffers by…
- meshData is not simple.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/a8d464f8a0e1e75e.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Rendering/Extensions/PolySortExtensions.cs:23
using System.Linq;
using Stride.Core;
using Stride.Core.Mathematics;
using Stride.Graphics;
using Stride.Graphics.Data;
using Stride.Rendering;
namespace Stride.Extensions
{
public static class PolySortExtensions
{
public static unsafe void SortMeshPolygons(this MeshDraw meshData, Vector3 viewDirectionForSorting)
{
// need to have alreade an vertex buffer
if (meshData.VertexBuffers == null)
throw new ArgumentException();
// For now, require a MeshData with an index buffer
if (meshData.IndexBuffer == null)
throw new NotImplementedException("The mesh Data needs to have index buffer");
if (meshData.VertexBuffers.Length != 1)
throw new NotImplementedException("Sorting not implemented for multiple vertex buffers by submeshdata");
if (viewDirectionForSorting == Vector3.Zero)
{
// By default to -Z if sorting is set to null
viewDirectionForSorting = -Vector3.UnitZ;
}
const uint PolySize = 3; // currently only triangle list are supported
var polyIndicesSize = PolySize * sizeof(int);
var vertexBuffer = meshData.VertexBuffers[0];
var oldIndexBuffer = meshData.IndexBuffer;
var vertexStride = vertexBuffer.Declaration.VertexStride;
// Generate the sort list
var sortList = new List<KeyValuePair<int, Vector3>>();
View on GitHub (pinned to 96fad776d2)