{"record":{"id":"028c58bfbebd3b2c","repo":"mrdoob/three.js","slug":"three-pmremgenerator-fromcubemap-called-before","errorCode":null,"errorMessage":"THREE.PMREMGenerator: .fromCubemap() called before the backend is initialized. Use \"await renderer.init();\" before using this method.","messagePattern":"THREE\\.PMREMGenerator: \\.fromCubemap\\(\\) 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":261,"sourceCode":"\n\t}\n\n\t/**\n\t * Generates a PMREM from an cubemap texture, which can be either LDR\n\t * or HDR. The ideal input cube size is 256 x 256, as this matches best\n\t * with the 256 x 256 cubemap output. The minimum supported input cube\n\t * size is 16 x 16 per face.\n\t *\n\t * @param {Texture} cubemap - The cubemap texture to be converted.\n\t * @param {?RenderTarget} [renderTarget=null] - The render target to use.\n\t * @return {RenderTarget} The resulting PMREM.\n\t * @see {@link PMREMGenerator#fromCubemapAsync}\n\t */\n\tfromCubemap( cubemap, renderTarget = null ) {\n\n\t\tif ( this._hasInitialized === false ) {\n\n\t\t\tthrow new Error( 'THREE.PMREMGenerator: .fromCubemap() called before the backend is initialized. Use \"await renderer.init();\" before using this method.' );\n\n\t\t}\n\n\t\treturn this._fromTexture( cubemap, renderTarget );\n\n\t}\n\n\t/**\n\t * Generates a PMREM from an cubemap texture, which can be either LDR\n\t * or HDR. The ideal input cube size is 256 x 256,\n\t * with the 256 x 256 cubemap output.\n\t *\n\t * @deprecated\n\t * @param {Texture} cubemap - The cubemap texture to be converted.\n\t * @param {?RenderTarget} [renderTarget=null] - The render target to use.\n\t * @return {Promise<RenderTarget>} The resulting PMREM.\n\t * @see {@link PMREMGenerator#fromCubemap}\n\t */","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/mrdoob/three.js/blob/da05705fa31f02710c19772a2aa70c7454807f0c/src/renderers/common/extras/PMREMGenerator.js#L243-L279","documentation":"Thrown by PMREMGenerator.fromCubemap() when the renderer is not yet initialized. Like the other from* methods, generating a PMREM from a cubemap texture requires the live GPU backend, and _hasInitialized delegates to renderer.hasInitialized().","triggerScenarios":"Calling `pmrem.fromCubemap(cubeTexture)` on a PMREMGenerator whose renderer has not yet had `await renderer.init()` resolve. Typical when converting a preloaded cube environment to PMREM.","commonSituations":"Cube-environment baking at startup. Migrating from the deprecated fromCubemapAsync without the explicit init await. Pre-converting a cube map before the first render.","solutions":["Call `await renderer.init();` before `pmrem.fromCubemap(cube)`.","Use the deprecated `await pmrem.fromCubemapAsync(cube)` (inits internally).","Defer the conversion until after the first frame has rendered."],"exampleFix":"// before\nconst renderer = new WebGPURenderer();\nconst pmrem = new PMREMGenerator(renderer);\nconst envMap = pmrem.fromCubemap(cubeMap); // throws\n\n// after\nconst renderer = new WebGPURenderer();\nawait renderer.init();\nconst pmrem = new PMREMGenerator(renderer);\nconst envMap = pmrem.fromCubemap(cubeMap);","handlingStrategy":"validation","validationCode":"async function safeFromCubemap(pmrem, cube) {\n  if (!pmrem._renderer.hasInitialized()) await pmrem._renderer.init();\n  return pmrem.fromCubemap(cube);\n}","typeGuard":"function pmremReady(pmrem) {\n  return pmrem._renderer && typeof pmrem._renderer.hasInitialized === 'function' && pmrem._renderer.hasInitialized();\n}","tryCatchPattern":"try {\n  return pmrem.fromCubemap(cube);\n} catch (e) {\n  if (/fromCubemap\\(\\) called before/.test(e.message)) { await pmrem._renderer.init(); return pmrem.fromCubemap(cube); }\n  else throw e;\n}","preventionTips":["Await renderer.init() before PMREM.fromCubemap.","Ensure the source cube texture is loaded and the renderer initialized before conversion.","Centralize environment-map generation behind an async helper."],"tags":["webgpu","lifecycle","async-init","pmrem","environment-map","cubemap"],"backgroundTag":null,"analyzedSha":"da05705fa31f02710c19772a2aa70c7454807f0c","analyzedAt":"2026-08-12T22:51:37.160Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}