{"record":{"id":"d48b28d6edad9d30","repo":"BabylonJS/Babylon.js","slug":"framegraph-a-pass-must-be-created-during-a-task-r","errorCode":null,"errorMessage":"FrameGraph: A pass must be created during a Task.record execution only.","messagePattern":"FrameGraph: A pass must be created during a Task\\.record execution only\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/FrameGraph/frameGraph.ts","lineNumber":225,"sourceCode":"     * @returns The render pass created\r\n     */\r\n    public addRenderPass(name: string, whenTaskDisabled = false): FrameGraphRenderPass {\r\n        return this._addPass(name, FrameGraphPassType.Render, whenTaskDisabled) as FrameGraphRenderPass;\r\n    }\r\n\r\n    /**\r\n     * Adds an object list pass to a task. This method can only be called during a Task.record execution.\r\n     * @param name The name of the pass\r\n     * @param whenTaskDisabled If true, the pass will be added to the list of passes to execute when the task is disabled (default is false)\r\n     * @returns The object list pass created\r\n     */\r\n    public addObjectListPass(name: string, whenTaskDisabled = false): FrameGraphObjectListPass {\r\n        return this._addPass(name, FrameGraphPassType.ObjectList, whenTaskDisabled) as FrameGraphObjectListPass;\r\n    }\r\n\r\n    private _addPass(name: string, passType: FrameGraphPassType, whenTaskDisabled = false): FrameGraphPass<FrameGraphContext> | FrameGraphRenderPass {\r\n        if (!this._currentProcessedTask) {\r\n            throw new Error(\"FrameGraph: A pass must be created during a Task.record execution only.\");\r\n        }\r\n\r\n        let pass: FrameGraphPass<FrameGraphContext> | FrameGraphRenderPass;\r\n\r\n        switch (passType) {\r\n            case FrameGraphPassType.Render:\r\n                pass = new FrameGraphRenderPass(name, this._currentProcessedTask, this._renderContext, this._engine);\r\n                break;\r\n            case FrameGraphPassType.ObjectList:\r\n                pass = new FrameGraphObjectListPass(name, this._currentProcessedTask, this._passContext, this._engine);\r\n                break;\r\n            default:\r\n                pass = new FrameGraphPass(name, this._currentProcessedTask, this._passContext);\r\n                break;\r\n        }\r\n\r\n        this._currentProcessedTask._addPass(pass, whenTaskDisabled);\r\n\r","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/FrameGraph/frameGraph.ts#L207-L243","documentation":"FrameGraph._addPass() throws when a pass (render pass or object list pass) is created while no task is currently being recorded. Passes are owned by tasks; creating one outside Task.record() execution would leave it orphaned in the graph, so the frame graph forbids it.","triggerScenarios":"Calling frameGraph.addRenderPass()/addObjectListPass()/addPass() from application code outside any task's record(), or from a custom task whose record() is not being executed by frameGraph.build() (e.g. calling task.record() directly without going through the frame graph build loop).","commonSituations":"Manually invoking record() on a custom task instead of using frameGraph.build(); creating render passes at setup time in initialization code; a task holding a stale frameGraph reference whose build was already completed.","solutions":["Create passes only inside your custom task's record() method, invoked via frameGraph.build().","Do not call task.record() directly; add the task with frameGraph.addTask(task) and build the graph.","If you need pass-like work outside a task, wrap it in a small custom FrameGraphTask and add it to the graph."],"exampleFix":"// before\nconst pass = frameGraph.addRenderPass('myPass'); // outside any task\n// after\nclass MyTask extends FrameGraphTask {\n  public record() {\n    const pass = this._frameGraph.addRenderPass(this.name);\n    pass.setExecuteFunc((ctx) => { /* ... */ });\n  }\n}\nframeGraph.addTask(new MyTask('myTask'));\nframeGraph.build();","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const pass = frameGraph.addRenderPass('x');\n} catch (e) {\n  if (String(e.message).includes('Task.record execution only')) {\n    // move pass creation into a FrameGraphTask.record()\n  } else {\n    throw e;\n  }\n}","preventionTips":["Create passes exclusively inside custom task record() methods.","Never call task.record() manually; use addTask + build()."],"tags":["babylonjs","framegraph","pass-lifecycle","misuse"],"backgroundTag":"pass-created-outside-task-record","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}