stride3d/stride · error · ArgumentOutOfRangeException
Invalid PrimitiveType in PipelineStateDescription.
Error message
Invalid PrimitiveType in PipelineStateDescription.
What it means
The D3D12 backend maps each Stride PrimitiveType to a D3D12 PrimitiveTopologyType (Line, Triangle, or Patch). A PrimitiveType value outside the known line/triangle ranges and the valid PatchList range (PatchList..PatchList+32) is invalid, so the constructor throws ArgumentOutOfRangeException for the primitiveType field.
Solutions
- Set PrimitiveType to a defined value (TriangleList, TriangleStrip, LineList, PatchList, etc.)
- Validate the value before constructing the PipelineStateDescription
- Fix serialization/deserialization of the pipeline state so enum values round-trip correctly
Example fix
// before
var desc = new PipelineStateDescription { PrimitiveType = (PrimitiveType)99, ... };
// after
var desc = new PipelineStateDescription { PrimitiveType = PrimitiveType.TriangleList, ... }; Defensive patterns
Strategy: validation
Validate before calling
if (!Enum.IsDefined(typeof(PrimitiveType), primitiveType)) throw new InvalidOperationException($"Undefined PrimitiveType: {primitiveType}"); Type guard
bool IsValidPrimitive(PrimitiveType p) => p is PrimitiveType.LineList or PrimitiveType.LineStrip or PrimitiveType.TriangleList or PrimitiveType.TriangleStrip or PrimitiveType.TriangleListWithAdjacency or PrimitiveType.TriangleStripWithAdjacency or (p >= PrimitiveType.PatchList && p < PrimitiveType.PatchList + 32);
Try / catch
try { state = PipelineState.New(device, desc); } catch (ArgumentOutOfRangeException) { /* invalid PrimitiveType value */ throw; } Prevention
- Only assign defined PrimitiveType enum values
- Avoid casting raw ints to PrimitiveType from serialized data without validation
When it happens
Trigger: Setting PipelineStateDescription.PrimitiveType to an undefined/out-of-range enum value (bad cast, corrupted data, value from another enum).
Common situations: PrimitiveType value deserialized from a serialized pipeline state that no longer matches the enum; arithmetic on PrimitiveType producing an invalid value; passing raw ints cast to PrimitiveType.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Invalid Shader stage specified in the Effect bytecode.
- Type [ ] is not a primitive
- The specified semantic name is too long. Usually it should…
- Element size cannot be less or equal 0 for structured buffer
- D3D12: Staging buffers can't be created with initial data.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/2a5976b603c652c8.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Graphics/Direct3D12/PipelineState.Direct3D12.cs:505
return primitiveType switch
{
PrimitiveType.Undefined => PrimitiveTopologyType.Undefined,
PrimitiveType.PointList => PrimitiveTopologyType.Point,
PrimitiveType.LineList or
PrimitiveType.LineStrip or
PrimitiveType.LineListWithAdjacency or
PrimitiveType.LineStripWithAdjacency => PrimitiveTopologyType.Line,
PrimitiveType.TriangleList or
PrimitiveType.TriangleStrip or
PrimitiveType.TriangleListWithAdjacency or
PrimitiveType.TriangleStripWithAdjacency => PrimitiveTopologyType.Triangle,
>= PrimitiveType.PatchList and < PrimitiveType.PatchList + 32 => PrimitiveTopologyType.Patch,
_ => throw new ArgumentOutOfRangeException(nameof(primitiveType), "Invalid PrimitiveType in PipelineStateDescription.")
};
}
//
// Prepares the input layout description from the input elements.
//
InputLayoutDesc PrepareInputLayout(InputElementDescription[] inputElements, List<ShaderInputAttributeDescription> inputAttributes)
{
if (inputElements is null || inputElements.Length == 0)
{
return default;
}
var inputElementsBufferSize = inputElements.Length * sizeof(InputElementDesc);
var inputElementsBuffer = AllocateTempMemory(inputElementsBufferSize);
var dstInputElements = (InputElementDesc*) inputElementsBuffer;
View on GitHub (pinned to 96fad776d2)