{"record":{"id":"2283969a0c3805fa","repo":"stride3d/stride","slug":"cannot-find-type-instruction-for-id-typeid","errorCode":null,"errorMessage":"Cannot find type instruction for id {typeId}","messagePattern":"Cannot find type instruction for id (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Parsers/Core/ConstantExpression.cs","lineNumber":129,"sourceCode":"                        };\n                        return new IntConstExpr(val);\n                    }\n                    else if (typeInst.Op == Op.OpTypeFloat)\n                    {\n                        var type = new OpTypeFloat(typeInst);\n                        double val = type switch\n                        {\n                            { Width: 16 } => (double)operand.ToLiteral<Half>(),\n                            { Width: 32 } => operand.ToLiteral<float>(),\n                            { Width: 64 } => operand.ToLiteral<double>(),\n                            _ => throw new NotImplementedException($\"Unsupported float width {type.Width}\"),\n                        };\n                        return new FloatConstExpr(val);\n                    }\n                    else\n                        throw new NotImplementedException($\"Unsupported constant type {typeInst.Op}\");\n                }\n                throw new InvalidOperationException($\"Cannot find type instruction for id {typeId}\");\n            }\n\n            case Op.OpConstantStringSDSL:\n            {\n                var operand = inst.Data.Get(\"literalString\");\n                return new StringConstExpr(operand.ToLiteral<string>());\n            }\n\n            case Op.OpGenericParameterSDSL:\n            case Op.OpGenericReferenceSDSL:\n            {\n                var genParam = (OpGenericParameterSDSL)inst;\n                return new GenericParamExpr(genParam.Index, genParam.DeclaringClass);\n            }\n\n            case Op.OpConstantComposite:\n            case Op.OpSpecConstantComposite:\n            {","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Parsers/Core/ConstantExpression.cs#L111-L147","documentation":"ConstantExpression.ParseInstruction throws this InvalidOperationException when an OpConstant/OpSpecConstant references a result-type id that does not exist in the SPIR-V buffer being parsed. The parser needs the OpTypeInt/OpTypeFloat instruction to know how to decode the literal; without it, decoding is impossible.","triggerScenarios":"Calling ConstantExpression.ParseFromBuffer with a buffer that is a fragment/extract (e.g. produced by ExtractConstantFromBuffer or EmitToBuffer) where the type-defining instruction was not copied in, or passing an id from a different buffer than the one containing its type declarations.","commonSituations":"Manually splicing instructions between SPIR-V buffers; truncating a buffer and losing type declarations; mixing ids from two different SpirvBuffer instances; using ParseFromBuffer on output of EmitToBuffer when the type was never emitted into the temp context.","solutions":["Ensure the complete buffer (including all OpType* instructions) is passed to ParseFromBuffer, not a partial extract.","Verify the constantId belongs to the same buffer instance passed as the 'buffer' argument.","Emit the type instruction into the buffer before the constant (e.g. via context.GetOrRegister before compiling the constant).","Check with buffer.TryGetInstructionById(typeId, ...) in a pre-check to fail early with a clearer message."],"exampleFix":"// before: parsing from a stripped buffer\nvar expr = ConstantExpression.ParseFromBuffer(constId, strippedBuffer, context); // throws\n// after: emit the type first so it is present in the buffer\ncontext.GetOrRegister(ScalarType.Int);\nvar expr = ConstantExpression.ParseFromBuffer(constId, context.GetBuffer(), context);","handlingStrategy":"validation","validationCode":"static bool TypeIsPresent(SpirvBuffer buffer, int constantId)\n    => buffer.TryGetInstructionById(constantId, out var inst)\n       && inst.Op is Op.OpConstant or Op.OpSpecConstant\n       && buffer.TryGetInstructionById(inst.Data.Memory.Span[1], out _);","typeGuard":null,"tryCatchPattern":"try\n{\n    var expr = ConstantExpression.ParseFromBuffer(id, buffer, context);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Cannot find type instruction\"))\n{\n    // buffer is incomplete or id belongs to another buffer — re-emit with full types\n}","preventionTips":["Always pass the complete buffer containing the type declarations, not an extract.","Never mix ids across different SpirvBuffer instances.","Emit the constant's type into the context before compiling the constant."],"tags":["spirv","shader-parsing","lookup-failure","buffer"],"backgroundTag":"resource-not-found","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"}