{"record":{"id":"c5624e0e9a21c1ff","repo":"BabylonJS/Babylon.js","slug":"no-active-scene-c5624e","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/perfTraceCommandService.ts","lineNumber":25,"sourceCode":"import \"core/Misc/PerformanceViewer/performanceViewerSceneExtension\";\r\n\r\n/**\r\n * Service that registers CLI commands for performance tracing using the PerformanceViewerCollector.\r\n * start-perf-trace begins collecting data, stop-perf-trace stops and returns the collected data as JSON.\r\n */\r\nexport const PerfTraceCommandServiceDefinition: ServiceDefinition<[], [IBridgeCommandRegistry, ISceneContext]> = {\r\n    friendlyName: \"Perf Trace Command Service\",\r\n    consumes: [BridgeCommandRegistryIdentity, SceneContextIdentity],\r\n    factory: (commandRegistry, sceneContext) => {\r\n        let perfCollector: PerformanceViewerCollector | undefined;\r\n\r\n        const startReg = commandRegistry.addCommand({\r\n            id: \"start-perf-trace\",\r\n            description: \"Start collecting performance trace data.\",\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                if (perfCollector?.isStarted) {\r\n                    return \"Performance trace is already running.\";\r\n                }\r\n\r\n                perfCollector = scene.getPerfCollector();\r\n                perfCollector.stop();\r\n                perfCollector.clear(false);\r\n                perfCollector.addCollectionStrategies(...DefaultPerfStrategies);\r\n                perfCollector.start(true);\r\n\r\n                return \"Performance trace started.\";\r\n            },\r\n        });\r\n\r\n        const stopReg = commandRegistry.addCommand({\r\n            id: \"stop-perf-trace\",\r","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/inspector-v2/src/services/cli/perfTraceCommandService.ts#L7-L43","documentation":"Thrown by the 'start-perf-trace' inspector CLI command when sceneContext.currentScene is null/undefined. Performance tracing instruments a live Babylon scene, so there is nothing to trace without an active scene. This fails fast before the perf collector is started.","triggerScenarios":"Executing 'start-perf-trace' before any scene has been created, or after the scene was disposed/cleared, or when the inspector is attached to a context whose sceneContext was never wired to a running engine.","commonSituations":"Running the inspector/CLI agent at startup before the engine creates the first scene; scene disposed during hot-reload; connecting the inspector to a headless bootstrap that never initializes a scene.","solutions":["Create/switch to a scene first (run the scene-creation command or wait for app initialization) and retry start-perf-trace.","If scripting, gate the trace start on scene readiness: await the app's 'scene ready' event before invoking the command.","Verify the inspector is attached to the same sceneContext the application actually uses (not a detached second instance)."],"exampleFix":"// before\nawait execute(\"start-perf-trace\", {}); // scene not created yet\n// after\nawait onSceneReady();\nawait execute(\"start-perf-trace\", {});","handlingStrategy":"try-catch","validationCode":"if (!sceneContext.currentScene) throw new Error(\"Cannot start perf trace: no active scene. Create a scene first.\");","typeGuard":"function hasActiveScene(ctx: { currentScene: unknown }): boolean { return ctx.currentScene != null; }","tryCatchPattern":"try {\n  await startPerfTrace();\n} catch (e) {\n  if (e instanceof Error && e.message === \"No active scene.\") {\n    await waitForSceneReady();\n    await startPerfTrace();\n  } else throw e;\n}","preventionTips":["Sequence CLI/agent actions after scene-creation completes (await 'scene ready').","Re-check currentScene after hot reloads; dispose can null it.","Confirm the inspector is bound to the app's real sceneContext."],"tags":["cli","scene","lifecycle"],"backgroundTag":"no-active-scene","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}