{"record":{"id":"beb432ecba245f44","repo":"stride3d/stride","slug":"could-not-find-start-of-method-functionid","errorCode":null,"errorMessage":"Could not find start of method {functionId}","messagePattern":"Could not find start of method (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Parsers/Spirv/Building/Builder.Functions.cs","lineNumber":106,"sourceCode":"        method.Type = methodType with { ParameterTypes = parameterTypes };\n\n        // Find OpFunctionParameter and remove it\n        var functionParameter = GetFunctionParameter(buffer, method, argIndex);\n        functionParameter.ResultType = context.GetOrRegister(newType);\n    }\n\n    public static (int Start, int End) FindMethodBounds(SpirvBuffer buffer, int functionId)\n    {\n        int? start = null;\n        for (var index = 0; index < buffer.Count; index++)\n        {\n            var instruction = buffer[index];\n            if (instruction.Op is Op.OpFunction && ((OpFunction)instruction).ResultId == functionId)\n                start = index;\n            if (instruction.Op is Op.OpFunctionEnd && start is int startIndex)\n                return (startIndex, index + 1);\n        }\n        throw new InvalidOperationException($\"Could not find start of method {functionId}\");\n    }\n\n}\n","sourceCodeStart":88,"sourceCodeEnd":110,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Parsers/Spirv/Building/Builder.Functions.cs#L88-L110","documentation":"FindMethodBounds locates the (start,end) instruction range of a function by scanning for its OpFunction and matching OpFunctionEnd. It throws InvalidOperationException when no OpFunction with the given result id was found (or its OpFunctionEnd was never reached), so the method bounds cannot be determined.","triggerScenarios":"Calling FindMethodBounds with a functionId that doesn't exist in the buffer — e.g. the function was removed, the id is stale after a rewrite, or the buffer only contains part of the module; also when an OpFunction exists without a closing OpFunctionEnd (corrupt/partial emission).","commonSituations":"Calling GetFunctionParameter (which uses FindMethodBounds) after the function was stripped by an optimization pass, or with an id captured before SPIR-V buffers were rebuilt during shader patching.","solutions":["Verify the functionId is valid and still present in the buffer (scan for OpFunction with that ResultId).","Re-resolve the function id from the symbol table after any pass that rebuilds the buffer.","Ensure the function was fully emitted (OpFunctionEnd present) before querying bounds.","Add logging of the requested functionId and buffer contents to diagnose stale ids."],"exampleFix":"// before\nvar (start, end) = Builder.FindMethodBounds(buffer, staleFunctionId);\n// after\nif (!TryGetFunctionId(symbolTable, method, out var functionId))\n    throw new InvalidOperationException($\"Function for {method} not yet emitted\");\nvar (start, end) = Builder.FindMethodBounds(buffer, functionId);","handlingStrategy":"validation","validationCode":"bool exists = Enumerable.Range(0, buffer.Count).Any(i => buffer[i] is OpFunction f && f.ResultId == functionId);","typeGuard":"bool functionInBuffer = buffer.Any(op => op is OpFunction f && f.ResultId == functionId);","tryCatchPattern":"try { var (s,e) = Builder.FindMethodBounds(buffer, functionId); } catch (InvalidOperationException ex) { /* function removed or id stale — re-resolve from symbol table */ throw; }","preventionTips":["Re-resolve function ids after any pass that rebuilds the buffer","Confirm the function was fully emitted (OpFunctionEnd present)","Check the function wasn't stripped by an optimization/patching pass","Log the requested functionId when bounds lookup fails"],"tags":["spirv","shader-compiler","function-not-found"],"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-23T08:17:48.524Z"}