{"record":{"id":"2a5976b603c652c8","repo":"stride3d/stride","slug":"invalid-primitivetype-in-pipelinestatedescription","errorCode":null,"errorMessage":"Invalid PrimitiveType in PipelineStateDescription.","messagePattern":"Invalid PrimitiveType in PipelineStateDescription\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/Direct3D12/PipelineState.Direct3D12.cs","lineNumber":505,"sourceCode":"                return primitiveType switch\n                {\n                    PrimitiveType.Undefined => PrimitiveTopologyType.Undefined,\n\n                    PrimitiveType.PointList => PrimitiveTopologyType.Point,\n\n                    PrimitiveType.LineList or\n                    PrimitiveType.LineStrip or\n                    PrimitiveType.LineListWithAdjacency or\n                    PrimitiveType.LineStripWithAdjacency => PrimitiveTopologyType.Line,\n\n                    PrimitiveType.TriangleList or\n                    PrimitiveType.TriangleStrip or\n                    PrimitiveType.TriangleListWithAdjacency or\n                    PrimitiveType.TriangleStripWithAdjacency => PrimitiveTopologyType.Triangle,\n\n                    >= PrimitiveType.PatchList and < PrimitiveType.PatchList + 32 => PrimitiveTopologyType.Patch,\n\n                    _ => throw new ArgumentOutOfRangeException(nameof(primitiveType), \"Invalid PrimitiveType in PipelineStateDescription.\")\n                };\n            }\n\n            //\n            // Prepares the input layout description from the input elements.\n            //\n            InputLayoutDesc PrepareInputLayout(InputElementDescription[] inputElements, List<ShaderInputAttributeDescription> inputAttributes)\n            {\n                if (inputElements is null || inputElements.Length == 0)\n                {\n                    return default;\n                }\n\n                var inputElementsBufferSize = inputElements.Length * sizeof(InputElementDesc);\n                var inputElementsBuffer = AllocateTempMemory(inputElementsBufferSize);\n\n                var dstInputElements = (InputElementDesc*) inputElementsBuffer;\n","sourceCodeStart":487,"sourceCodeEnd":523,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/Direct3D12/PipelineState.Direct3D12.cs#L487-L523","documentation":"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.","triggerScenarios":"Setting PipelineStateDescription.PrimitiveType to an undefined/out-of-range enum value (bad cast, corrupted data, value from another enum).","commonSituations":"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.","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"],"exampleFix":"// before\nvar desc = new PipelineStateDescription { PrimitiveType = (PrimitiveType)99, ... };\n// after\nvar desc = new PipelineStateDescription { PrimitiveType = PrimitiveType.TriangleList, ... };","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(PrimitiveType), primitiveType)) throw new InvalidOperationException($\"Undefined PrimitiveType: {primitiveType}\");","typeGuard":"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);","tryCatchPattern":"try { state = PipelineState.New(device, desc); } catch (ArgumentOutOfRangeException) { /* invalid PrimitiveType value */ throw; }","preventionTips":["Only assign defined PrimitiveType enum values","Avoid casting raw ints to PrimitiveType from serialized data without validation"],"tags":["direct3d12","pipeline-state","primitive-type"],"backgroundTag":"invalid-enum-value","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"}