{"record":{"id":"b713486b40e1d45a","repo":"BabylonJS/Babylon.js","slug":"invalid-scene-provided-to-getinspectorgizmomanager","errorCode":null,"errorMessage":"Invalid scene provided to GetInspectorGizmoManager","messagePattern":"Invalid scene provided to GetInspectorGizmoManager","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/inspector/src/inspectorGizmoManager.ts","lineNumber":22,"sourceCode":"import { GizmoManager } from \"core/Gizmos/gizmoManager\";\r\nimport { FrameGraphUtils } from \"core/FrameGraph/frameGraphUtils\";\r\n\r\nfunction CreateInspectorGizmoManager(scene: Scene): GizmoManager {\r\n    const layer1 = scene.frameGraph ? FrameGraphUtils.CreateUtilityLayerRenderer(scene.frameGraph) : new UtilityLayerRenderer(scene);\r\n    const layer2 = scene.frameGraph ? FrameGraphUtils.CreateUtilityLayerRenderer(scene.frameGraph) : new UtilityLayerRenderer(scene);\r\n    const gizmoManager = new GizmoManager(scene, undefined, layer1, layer2);\r\n    scene.reservedDataStore ??= {};\r\n    scene.reservedDataStore.gizmoManager = gizmoManager;\r\n    return gizmoManager;\r\n}\r\n\r\nexport function GetInspectorGizmoManager(scene: Nullable<Scene> | undefined, create: true): GizmoManager;\r\nexport function GetInspectorGizmoManager(scene: Nullable<Scene> | undefined, create: false): Nullable<GizmoManager>;\r\nexport function GetInspectorGizmoManager(scene: Nullable<Scene> | undefined, create: boolean): Nullable<GizmoManager> {\r\n    let gizmoManager = scene && scene.reservedDataStore && scene.reservedDataStore.gizmoManager ? (scene.reservedDataStore.gizmoManager as GizmoManager) : null;\r\n    if (!gizmoManager && create) {\r\n        if (!scene) {\r\n            throw new Error(\"Invalid scene provided to GetInspectorGizmoManager\");\r\n        }\r\n        gizmoManager = CreateInspectorGizmoManager(scene);\r\n    }\r\n    return gizmoManager;\r\n}\r\n\r\nexport function DisposeInspectorGizmoManager(scene: Nullable<Scene> | undefined): void {\r\n    const gizmoManager = GetInspectorGizmoManager(scene, false);\r\n    if (!gizmoManager) {\r\n        return;\r\n    }\r\n    gizmoManager.dispose();\r\n    scene!.reservedDataStore.gizmoManager = null;\r\n}\r\n","sourceCodeStart":4,"sourceCodeEnd":37,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/inspector/src/inspectorGizmoManager.ts#L4-L37","documentation":"GetInspectorGizmoManager looks up (or, with create=true, creates) the inspector's GizmoManager stored on scene.reservedDataStore. It throws when create=true is requested but the passed scene is null/undefined, since a gizmo manager cannot be created without a scene.","triggerScenarios":"Calling gizmoManager/toggleGizmo/manager accessors (which call GetInspectorGizmoManager(scene, true)) before the inspector is attached to a scene, or after the scene reference was cleared to null, while asking to create the manager.","commonSituations":"Toggling gizmos in the inspector UI before scene selection completes; holding a stale inspector reference after scene disposal; calling inspector helpers from code that never received the scene (e.g. during early init).","solutions":["Ensure a valid Scene instance is created and passed to the inspector before calling gizmo-related APIs.","Guard calls with a scene null-check before invoking gizmoManager/toggleGizmo.","If the scene was disposed, reinitialize the inspector with the new scene instead of reusing stale references.","Pass create=false first (via the overload) to probe existence without triggering the throw."],"exampleFix":"// before\nconst manager = GetInspectorGizmoManager(maybeScene, true); // throws if null\n// after\nif (!maybeScene) return null;\nconst manager = GetInspectorGizmoManager(maybeScene, true);","handlingStrategy":"type-guard","validationCode":"function canGetGizmoManager(scene: unknown): boolean {\n  return !!scene && typeof (scene as Scene).getEngine === \"function\";\n}","typeGuard":"function isScene(s: unknown): s is Scene {\n  return !!s && typeof (s as Scene).getEngine === \"function\" && typeof (s as Scene).reservedDataStore !== \"undefined\";\n}","tryCatchPattern":"try {\n  const mgr = GetInspectorGizmoManager(scene, true);\n} catch (e) {\n  if (e instanceof Error && e.message === \"Invalid scene provided to GetInspectorGizmoManager\") {\n    console.warn(\"Inspector not attached to a scene; gizmos unavailable.\");\n  } else throw e;\n}","preventionTips":["Only call inspector gizmo APIs after the inspector is bound to a live scene","Clear/refresh inspector references on scene disposal","Use the create=false overload to probe existence safely","Null-check scene at every call site that forwards it to the inspector"],"tags":["inspector","gizmo","null-check","scene"],"backgroundTag":"null-scene-reference","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}