{"record":{"id":"8af7c02bc1e02f5e","repo":"BabylonJS/Babylon.js","slug":"no-camera-available-for-screenshot","errorCode":null,"errorMessage":"No camera available for screenshot.","messagePattern":"No camera available for screenshot\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/inspector-v2/src/services/cli/screenshotCommandService.ts","lineNumber":64,"sourceCode":"                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\n\r\n                if (!camera) {\r\n                    throw new Error(\"No camera available for screenshot.\");\r\n                }\r\n\r\n                const precision = args.precision !== undefined ? Number(args.precision) : 1;\r\n                if (!Number.isFinite(precision) || precision <= 0) {\r\n                    throw new Error(\"precision must be a finite number greater than 0.\");\r\n                }\r\n\r\n                let width: number | undefined;\r\n                if (args.width !== undefined) {\r\n                    width = Number(args.width);\r\n                    if (!Number.isFinite(width) || width <= 0 || !Number.isInteger(width)) {\r\n                        throw new Error(\"width must be a finite positive integer.\");\r\n                    }\r\n                }\r\n\r\n                let height: number | undefined;\r\n                if (args.height !== undefined) {\r\n                    height = Number(args.height);\r","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/inspector-v2/src/services/cli/screenshotCommandService.ts#L46-L82","documentation":"Thrown by the 'screenshot' command when no camera could be resolved at all: no cameraUniqueId was given and both the frame-graph main camera (FrameGraphUtils.FindMainCamera) and scene.activeCamera are null/undefined. Rendering requires a camera, so the command aborts.","triggerScenarios":"Executing screenshot on a scene with zero cameras, or where activeCamera was never assigned and there is no frame graph (or the frame graph has no main camera).","commonSituations":"Building the scene procedurally and forgetting to add a camera or set scene.activeCamera; clearing all cameras mid-session; using a custom render pipeline where FindMainCamera returns null.","solutions":["Add a camera to the scene (e.g. new ArcRotateCamera/FreeCamera) and/or assign scene.activeCamera.","If using a frame graph, configure it so FrameGraphUtils.FindMainCamera can resolve a main camera.","Pass an explicit cameraUniqueId of an existing camera to bypass auto-resolution."],"exampleFix":"// before\nawait execute(\"screenshot\", {}); // scene has no cameras\n// after\nconst cam = new BABYLON.FreeCamera(\"cam\", new BABYLON.Vector3(0, 5, -10), scene);\nscene.activeCamera = cam;\nawait execute(\"screenshot\", {});","handlingStrategy":"type-guard","validationCode":"if (!scene.activeCamera && !scene.frameGraph) throw new Error(\"Screenshot needs a camera: set scene.activeCamera or pass cameraUniqueId.\");","typeGuard":"function hasResolvableCamera(scene: { activeCamera: unknown; frameGraph: unknown; cameras: unknown[] }): boolean {\n  return scene.activeCamera != null || scene.frameGraph != null || scene.cameras.length > 0;\n}","tryCatchPattern":"try {\n  await screenshot(args);\n} catch (e) {\n  if (e instanceof Error && e.message === \"No camera available for screenshot.\") {\n    scene.activeCamera = scene.cameras[0] ?? createDefaultCamera(scene);\n    return screenshot(args);\n  }\n  throw e;\n}","preventionTips":["Always create and assign a camera during scene setup.","In frame-graph scenes, ensure a main camera node is configured.","Check scene.cameras.length > 0 before invoking screenshot in scripts."],"tags":["cli","camera","screenshot","scene"],"backgroundTag":"missing-camera","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}