{"record":{"id":"dd7419a88c12c546","repo":"BabylonJS/Babylon.js","slug":"no-active-scene","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/entityQueryService.ts","lineNumber":107,"sourceCode":"    };\r\n}\r\n\r\nfunction MinimalSummary(entity: { uniqueId: number; name?: string }): IEntitySummary {\r\n    return {\r\n        uniqueId: entity.uniqueId,\r\n        name: entity.name,\r\n    };\r\n}\r\n\r\nfunction MakeQueryCommand<T>(collection: IEntityCollection<T>, sceneContext: ISceneContext): BridgeCommandDescriptor {\r\n    return {\r\n        id: collection.id,\r\n        description: collection.description,\r\n        args: [UniqueIdArg],\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 entities = collection.getEntities(scene);\r\n            if (!entities) {\r\n                return JSON.stringify([], null, 2);\r\n            }\r\n\r\n            if (!args.uniqueId) {\r\n                return JSON.stringify(\r\n                    entities.map((e) => collection.getSummary(e)),\r\n                    null,\r\n                    2\r\n                );\r\n            }\r\n\r\n            const id = parseInt(args.uniqueId, 10);\r\n            if (isNaN(id)) {\r\n                throw new Error(\"uniqueId must be a number.\");\r","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/inspector-v2/src/services/cli/entityQueryService.ts#L89-L125","documentation":"MakeQueryCommand builds CLI query commands whose executeAsync first reads sceneContext.currentScene; if no scene is active (null/undefined) it throws 'No active scene.' because entity collections can only be enumerated against a live Scene. This happens when a bridge/CLI query command runs before a scene is created or after it has been disposed.","triggerScenarios":"Executing any registered 'query-*' bridge/CLI command (e.g. query-meshes, query-materials) via the CLI/bridge while sceneContext.currentScene is null: before the engine creates a scene, after scene disposal, or in a context where the inspector is attached but no scene was ever registered.","commonSituations":"Running CLI queries in the inspector immediately after page load before the playground scene finishes creating; executing commands against a disposed scene; automation/agent tooling invoking bridge commands without first ensuring a scene exists; headless or test setups that register CLI services without initializing a scene.","solutions":["Ensure a scene exists before running the command — wait for the engine/scene creation (e.g. engine.runRenderLoop or the scene-ready event) before issuing query commands.","Guard the caller: check sceneContext.currentScene (or the engine's active scene) before invoking query-* commands and skip or queue them.","If the scene was disposed, recreate it (new Scene(engine)) and re-run the query.","In automation scripts, add a readiness poll that waits until the scene is available with a timeout."],"exampleFix":"// before: command may run before scene exists\nconst result = await bridge.execute(\"query-meshes\", {});\n\n// after: wait for an active scene\nasync function waitForScene(sceneContext, timeoutMs = 5000) {\n  const start = Date.now();\n  while (!sceneContext.currentScene) {\n    if (Date.now() - start > timeoutMs) throw new Error(\"Timed out waiting for active scene\");\n    await new Promise(r => setTimeout(r, 100));\n  }\n}\nawait waitForScene(sceneContext);\nconst result = await bridge.execute(\"query-meshes\", {});","handlingStrategy":"validation","validationCode":"function requireActiveScene(sceneContext) {\n  const scene = sceneContext?.currentScene;\n  if (!scene) throw new Error(\"Cannot run query: no active scene. Wait for scene creation first.\");\n  return scene;\n}","typeGuard":"function hasActiveScene(sceneContext) {\n  return Boolean(sceneContext && sceneContext.currentScene);\n}","tryCatchPattern":"try {\n  const result = await bridge.execute(\"query-meshes\", {});\n} catch (e) {\n  if (e.message === \"No active scene.\") {\n    console.warn(\"Scene not ready — deferring query until scene is created.\");\n    await waitForScene(sceneContext);\n    // retry the command here\n  } else {\n    throw e;\n  }\n}","preventionTips":["Gate CLI/bridge query commands behind a scene-ready signal.","In automation, poll sceneContext.currentScene with a timeout before querying.","Re-register or refresh CLI services when a scene is disposed and recreated.","Return an empty list or a clear 'scene not ready' result instead of executing queries against a disposed scene."],"tags":["scene","cli","lifecycle","inspector"],"backgroundTag":"no-active-scene","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}