{"record":{"id":"f5e6040ab82fe345","repo":"BabylonJS/Babylon.js","slug":"no-active-scene-f5e604","errorCode":null,"errorMessage":"No active scene.","messagePattern":"No active scene\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/inspector-v2/src/services/cli/screenshotCommandService.ts","lineNumber":43,"sourceCode":"                    name: \"width\",\r\n                    description: \"Screenshot width in pixels. When set, uses custom size mode.\",\r\n                    required: false,\r\n                },\r\n                {\r\n                    name: \"height\",\r\n                    description: \"Screenshot height in pixels. When set, uses custom size mode.\",\r\n                    required: false,\r\n                },\r\n                {\r\n                    name: \"precision\",\r\n                    description: \"Resolution multiplier (e.g. 2 for double resolution). Defaults to 1.\",\r\n                    required: false,\r\n                },\r\n            ],\r\n            executeAsync: async (args) => {\r\n                const scene = sceneContext.currentScene;\r\n                if (!scene) {\r\n                    throw new Error(\"No active scene.\");\r\n                }\r\n\r\n                const engine = scene.getEngine();\r\n\r\n                // Resolve camera: explicit uniqueId, or active/frame-graph camera.\r\n                let camera;\r\n                if (args.cameraUniqueId) {\r\n                    const cameraId = parseInt(args.cameraUniqueId, 10);\r\n                    if (isNaN(cameraId)) {\r\n                        throw new Error(\"cameraUniqueId must be a number.\");\r\n                    }\r\n                    camera = scene.cameras.find((c) => c.uniqueId === cameraId);\r\n                    if (!camera) {\r\n                        throw new Error(`No camera found with uniqueId ${cameraId}.`);\r\n                    }\r\n                } else {\r\n                    camera = scene.frameGraph ? FrameGraphUtils.FindMainCamera(scene.frameGraph) : scene.activeCamera;\r\n                }\r","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/inspector-v2/src/services/cli/screenshotCommandService.ts#L25-L61","documentation":"Thrown by the 'screenshot' CLI command when sceneContext.currentScene is null/undefined. Screenshots are captured by rendering through the active scene's engine, so an active scene is a hard prerequisite. This guard runs before camera resolution and any rendering.","triggerScenarios":"Executing 'screenshot' before the app creates a scene, after scene disposal, or while the inspector's sceneContext is pointed at a context with no current scene.","commonSituations":"An automation agent taking a screenshot immediately after inspector startup before first render; scene rebuilt during hot-reload leaving currentScene null; attaching the inspector to the wrong engine instance.","solutions":["Ensure the scene is created and rendered at least once, then retry the screenshot command.","In scripts, wait for a 'ready'/'first frame' signal before invoking screenshot.","Verify the inspector was registered with the same sceneContext/engine the app renders with."],"exampleFix":"// before\nawait execute(\"screenshot\", {}); // scene not ready\n// after\nawait waitForFirstRender();\nawait execute(\"screenshot\", {});","handlingStrategy":"try-catch","validationCode":"if (!sceneContext.currentScene) throw new Error(\"Cannot take screenshot: no active scene.\");","typeGuard":"function sceneAvailable(ctx: { currentScene: unknown }): boolean { return ctx.currentScene != null; }","tryCatchPattern":"try {\n  await screenshot(args);\n} catch (e) {\n  if (e instanceof Error && e.message === \"No active scene.\") {\n    await waitForFirstRender();\n    return screenshot(args); // one retry after readiness\n  }\n  throw e;\n}","preventionTips":["Wait for a first rendered frame before screenshotting in automation.","After scene disposal/rebuild, re-acquire the scene reference.","Verify inspector registration points at the rendering engine's context."],"tags":["cli","scene","screenshot","lifecycle"],"backgroundTag":"no-active-scene","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}