{"record":{"id":"9cb3f71579932566","repo":"stride3d/stride","slug":"constant-has-no-result-id","errorCode":null,"errorMessage":"Constant has no result id","messagePattern":"Constant has no result id","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"sources/shaders/Stride.Shaders.Parsers/Spirv/Building/Context.Constants.cs","lineNumber":32,"sourceCode":"    public Dictionary<(SymbolType Type, object Value), SpirvValue> LiteralConstants { get; } = [];\n\n    public int AddConstant<TScalar>(TScalar value)\n        where TScalar : INumber<TScalar>\n    {\n        var data = value switch\n        {\n            uint v => Buffer.AddData(new OpConstant<uint>(GetOrRegister(ScalarType.UInt), Bound++, v)),\n            int v => Buffer.AddData(new OpConstant<int>(GetOrRegister(ScalarType.Int), Bound++, v)),\n            ulong v => Buffer.AddData(new OpConstant<ulong>(GetOrRegister(ScalarType.UInt64), Bound++, v)),\n            long v => Buffer.AddData(new OpConstant<long>(GetOrRegister(ScalarType.Int64), Bound++, v)),\n            Half v => Buffer.AddData(new OpConstant<Half>(GetOrRegister(ScalarType.Half), Bound++, v)),\n            float v => Buffer.AddData(new OpConstant<float>(GetOrRegister(ScalarType.Float), Bound++, v)),\n            double v => Buffer.AddData(new OpConstant<double>(GetOrRegister(ScalarType.Double), Bound++, v)),\n            _ => throw new NotImplementedException()\n        };\n        if (InstructionInfo.GetInfo(data).GetResultIndex(out var index))\n            return data.Memory.Span[index + 1];\n        throw new Exception(\"Constant has no result id\");\n    }\n\n    public object GetConstantValue(int constantId)\n    {\n        if (Buffer.TryGetInstructionById(constantId, out var constant))\n        {\n            return ResolveConstantValue(constant);\n        }\n\n        throw new Exception(\"Cannot find constant instruction for id \" + constantId);\n    }\n\n    public bool TryGetConstantValue(int constantId, [MaybeNullWhen(false)] out object value, out int typeId)\n    {\n        if (Buffer.TryGetInstructionById(constantId, out var constant))\n        {\n            return TryGetConstantValue(constant, out value, out typeId);\n        }","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Parsers/Spirv/Building/Context.Constants.cs#L14-L50","documentation":"After AddConstant emits an OpConstant instruction into the SPIR-V buffer, it reads back the instruction's result-id slot (index+1) to return the newly allocated id. If InstructionInfo.GetInfo(data).GetResultIndex fails, the emitted instruction has no result-id operand — which should be impossible for a valid OpConstant — so the library throws 'Constant has no result id'. This indicates the instruction stream or the SPIR-V specification opcode metadata table is inconsistent.","triggerScenarios":"Calling AddConstant when the emitted data's opcode does not resolve to an instruction with a result-id operand — typically because the SPIR-V specification metadata (InstructionInfo) is missing or stale for OpConstant, or the buffer returned corrupted/truncated data.","commonSituations":"Version skew between the SPIR-V specification generator and the parser assembly; custom builds where InstructionInfo tables were regenerated from an incomplete spec; memory corruption of the emitted OpDataIndex.","solutions":["Regenerate/verify the SPIR-V InstructionInfo metadata so OpConstant declares a result-id operand.","Confirm the Buffer.AddData return value is a complete, well-formed instruction (opcode + word count + operands).","Update the Stride.Shaders.Parsers package/spec files to a matching version."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (!InstructionInfo.GetInfo(data).GetResultIndex(out _)) throw new InvalidOperationException(\"InstructionInfo metadata does not define a result id for the emitted constant\");","typeGuard":null,"tryCatchPattern":"try { return context.AddConstant(v); } catch (Exception ex) when (ex.Message == \"Constant has no result id\") { /* regenerate spec metadata / report toolchain bug */ }","preventionTips":["Keep SPIR-V specification metadata files in sync with the parser assembly version","Pin the Stride.Shaders.Parsers package and its spec generator to matching versions","Sanity-check emitted instruction word counts in CI"],"tags":["spirv","constant","internal-invariant","metadata"],"backgroundTag":"internal-invariant-violation","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"}