{"record":{"id":"f2a085062a222728","repo":"mrdoob/three.js","slug":"three-pmremgenerator-fromscene-called-before-t","errorCode":null,"errorMessage":"THREE.PMREMGenerator: .fromScene() called before the backend is initialized. Use \"await renderer.init();\" before using this method.","messagePattern":"THREE\\.PMREMGenerator: \\.fromScene\\(\\) called before the backend is initialized\\. Use \"await renderer\\.init\\(\\);\" before using this method\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/renderers/common/extras/PMREMGenerator.js","lineNumber":145,"sourceCode":"\t * @param {number} [options.size=256] - The texture size of the PMREM.\n\t * @param {Vector3} [options.position=origin] - The position of the internal cube camera that renders the scene.\n\t * @param {?RenderTarget} [options.renderTarget=null] - The render target to use.\n\t * @return {RenderTarget} The resulting PMREM.\n\t * @see {@link PMREMGenerator#fromScene}\n\t */\n\tfromScene( scene, sigma = 0, near = 0.1, far = 100, options = {} ) {\n\n\t\tconst {\n\t\t\tsize = 256,\n\t\t\tposition = _origin,\n\t\t\trenderTarget = null,\n\t\t} = options;\n\n\t\tthis._setSize( size );\n\n\t\tif ( this._hasInitialized === false ) {\n\n\t\t\tthrow new Error( 'THREE.PMREMGenerator: .fromScene() called before the backend is initialized. Use \"await renderer.init();\" before using this method.' );\n\n\t\t}\n\n\t\t_oldTarget = this._renderer.getRenderTarget();\n\t\t_oldActiveCubeFace = this._renderer.getActiveCubeFace();\n\t\t_oldActiveMipmapLevel = this._renderer.getActiveMipmapLevel();\n\n\t\tconst cubeUVRenderTarget = renderTarget || this._allocateTarget( true );\n\n\t\tthis._init( cubeUVRenderTarget );\n\n\t\tthis._sceneToCubeUV( scene, near, far, cubeUVRenderTarget, position );\n\n\t\tif ( sigma > 0 ) {\n\n\t\t\tthis._blur( cubeUVRenderTarget, 0, 0, sigma );\n\n\t\t}","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/mrdoob/three.js/blob/da05705fa31f02710c19772a2aa70c7454807f0c/src/renderers/common/extras/PMREMGenerator.js#L127-L163","documentation":"Thrown by PMREMGenerator.fromScene() when the underlying renderer has not been initialized. PMREMGenerator._hasInitialized delegates to renderer.hasInitialized(); generating a PMREM requires rendering a scene into a cubemap, so the GPU backend must already be live.","triggerScenarios":"Constructing `new PMREMGenerator(renderer)` and calling `.fromScene(scene)` before `await renderer.init()` has resolved. Common when generating an environment map at app startup.","commonSituations":"Environment-map baking at module load. Migrating from the deprecated fromSceneAsync without adding the explicit init await. Loading an HDR/scene-based environment before the first render.","solutions":["Call `await renderer.init();` before `pmrem.fromScene(scene)`.","Use the deprecated `await pmrem.fromSceneAsync(scene, ...)` which inits the renderer internally.","Defer PMREM generation until after the first render frame."],"exampleFix":"// before\nconst renderer = new WebGPURenderer();\nconst pmrem = new PMREMGenerator(renderer);\nconst envMap = pmrem.fromScene(scene); // throws\n\n// after\nconst renderer = new WebGPURenderer();\nawait renderer.init();\nconst pmrem = new PMREMGenerator(renderer);\nconst envMap = pmrem.fromScene(scene);","handlingStrategy":"validation","validationCode":"async function safeFromScene(pmrem, scene, opts) {\n  if (!pmrem._renderer.hasInitialized()) await pmrem._renderer.init();\n  return pmrem.fromScene(scene, opts);\n}","typeGuard":"function pmremReady(pmrem) {\n  return pmrem._renderer && typeof pmrem._renderer.hasInitialized === 'function' && pmrem._renderer.hasInitialized();\n}","tryCatchPattern":"try {\n  return pmrem.fromScene(scene);\n} catch (e) {\n  if (/fromScene\\(\\) called before/.test(e.message)) { await pmrem._renderer.init(); return pmrem.fromScene(scene); }\n  else throw e;\n}","preventionTips":["Await renderer.init() before constructing or using a PMREMGenerator.","Run environment-map baking in an async post-init phase.","Reuse a single initialized renderer for all PMREM work."],"tags":["webgpu","lifecycle","async-init","pmrem","environment-map"],"backgroundTag":null,"analyzedSha":"da05705fa31f02710c19772a2aa70c7454807f0c","analyzedAt":"2026-08-12T22:51:37.160Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}