{"record":{"id":"38b8353f9a2e89ee","repo":"BabylonJS/Babylon.js","slug":"no-active-scene-38b835","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/statsCommandService.ts","lineNumber":34,"sourceCode":"    consumes: [BridgeCommandRegistryIdentity, SceneContextIdentity],\r\n    factory: (commandRegistry, sceneContext) => {\r\n        let sceneInstrumentation: SceneInstrumentation | undefined;\r\n        let engineInstrumentation: EngineInstrumentation | undefined;\r\n\r\n        function disposeInstrumentation() {\r\n            sceneInstrumentation?.dispose();\r\n            sceneInstrumentation = undefined;\r\n            engineInstrumentation?.dispose();\r\n            engineInstrumentation = undefined;\r\n        }\r\n\r\n        const startPerfReg = commandRegistry.addCommand({\r\n            id: \"start-perf-instrumentation\",\r\n            description: \"Start scene and engine performance instrumentation for frame stats collection.\",\r\n            executeAsync: async () => {\r\n                const scene = sceneContext.currentScene;\r\n                if (!scene) {\r\n                    throw new Error(\"No active scene.\");\r\n                }\r\n\r\n                // Dispose any stale instrumentation (e.g. scene changed).\r\n                if (sceneInstrumentation && sceneInstrumentation.scene !== scene) {\r\n                    disposeInstrumentation();\r\n                }\r\n\r\n                if (sceneInstrumentation) {\r\n                    return \"Performance instrumentation is already running.\";\r\n                }\r\n\r\n                sceneInstrumentation = new SceneInstrumentation(scene);\r\n                sceneInstrumentation.captureActiveMeshesEvaluationTime = true;\r\n                sceneInstrumentation.captureRenderTargetsRenderTime = true;\r\n                sceneInstrumentation.captureFrameTime = true;\r\n                sceneInstrumentation.captureRenderTime = true;\r\n                sceneInstrumentation.captureInterFrameTime = true;\r\n                sceneInstrumentation.captureParticlesRenderTime = true;\r","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/inspector-v2/src/services/cli/statsCommandService.ts#L16-L52","documentation":"The `start-perf-instrumentation` CLI command requires an active scene from the inspector's scene context. When no scene has been loaded/opened (sceneContext.currentScene is null), there is nothing to instrument, so the command throws this error instead of silently starting no-op instrumentation.","triggerScenarios":"Running start-perf-instrumentation before any scene is created or attached in the inspector; after the engine/scene was disposed; in a headless session where scene initialization hasn't completed yet.","commonSituations":"Calling the CLI command during tool startup before the playground/app loads a scene; scene disposal racing with instrumentation commands; automating the inspector without first awaiting scene initialization.","solutions":["Load or create a scene first, then run start-perf-instrumentation","Wait for scene initialization (sceneContext.currentScene to be non-null / scene.whenReadyAsync()) before invoking the command","If a scene was disposed, re-create or re-select it in the inspector before instrumenting","Add a guard in automation scripts that polls for an active scene before issuing CLI commands"],"exampleFix":"// before\nawait cli.run(\"start-perf-instrumentation\", {});\n// after\nif (!sceneContext.currentScene) {\n    await waitForScene(sceneContext);\n}\nawait cli.run(\"start-perf-instrumentation\", {});","handlingStrategy":"validation","validationCode":"if (!sceneContext.currentScene) {\n    throw new Error(\"Cannot start instrumentation: no active scene. Load a scene first.\");\n}\nawait cli.run(\"start-perf-instrumentation\", {});","typeGuard":"function hasActiveScene(ctx: { currentScene: BABYLON.Scene | null }): ctx is { currentScene: BABYLON.Scene } {\n    return ctx.currentScene !== null && !ctx.currentScene.isDisposed;\n}","tryCatchPattern":"try {\n    await cli.run(\"start-perf-instrumentation\", {});\n} catch (err) {\n    if (String(err).includes(\"No active scene\")) {\n        await loadOrAwaitScene();\n        await cli.run(\"start-perf-instrumentation\", {});\n    } else {\n        throw err;\n    }\n}","preventionTips":["Always load/create a scene before issuing any scene-dependent CLI commands","Await scene initialization promises in automation before calling CLI tools","Re-check the scene context after engine disposal or scene switches","Centralize a \"wait for scene\" helper in scripts instead of assuming a scene exists"],"tags":["scene","cli","lifecycle"],"backgroundTag":"no-active-scene","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}