{"record":{"id":"1b43a2ae1b7cd570","repo":"mrdoob/three.js","slug":"three-renderer-resetstate-called-before-the-ba","errorCode":null,"errorMessage":"THREE.Renderer: .resetState() called before the backend is initialized. Use \"await renderer.init();\" before using this method.","messagePattern":"THREE\\.Renderer: \\.resetState\\(\\) 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/Renderer.js","lineNumber":2313,"sourceCode":"\tsetScissorTest( boolean ) {\n\n\t\tthis._canvasTarget.setScissorTest( boolean );\n\n\t\t// TODO: Move it to CanvasTarget event listener.\n\n\t\tthis.backend.setScissorTest( boolean );\n\n\t}\n\n\t/**\n\t * Resets the backend's internal state cache. Useful when the rendering context is shared with\n\t * other libraries that change the state. A no-op for the WebGPU backend.\n\t */\n\tresetState() {\n\n\t\tif ( this._initialized === false ) {\n\n\t\t\tthrow new Error( 'THREE.Renderer: .resetState() called before the backend is initialized. Use \"await renderer.init();\" before using this method.' );\n\n\t\t}\n\n\t\tthis.backend.resetState();\n\n\t}\n\n\t/**\n\t * Returns the viewport definition.\n\t *\n\t * @param {Vector4} target - The method writes the result in this target object.\n\t * @return {Vector4} The viewport definition.\n\t */\n\tgetViewport( target ) {\n\n\t\treturn this._canvasTarget.getViewport( target );\n\n\t}","sourceCodeStart":2295,"sourceCodeEnd":2331,"githubUrl":"https://github.com/mrdoob/three.js/blob/da05705fa31f02710c19772a2aa70c7454807f0c/src/renderers/common/Renderer.js#L2295-L2331","documentation":"Thrown by Renderer.resetState() when the backend has not been initialized. resetState rebuilds the backend's cached GL state, so it requires a live backend; calling it before init has no state cache to reset.","triggerScenarios":"Calling renderer.resetState() synchronously after constructing an async Renderer/WebGPURenderer without awaiting init; sharing the context with another library and resetting state during early setup.","commonSituations":"Integrating three.js with another WebGL library (e.g. map/Chart libs) and calling resetState in an early lifecycle hook; porting from WebGLRenderer where resetState was safe immediately.","solutions":["await renderer.init() before the first resetState() call.","Defer context-sharing/reset logic until after init resolves.","For WebGPU backends, resetState is a no-op — confirm you actually need it; if not, remove the call.","Gate resetState behind an initialized flag in your integration code."],"exampleFix":"// before\nconst renderer = new THREE.WebGPURenderer();\nrenderer.resetState(); // throws\n\n// after\nconst renderer = new THREE.WebGPURenderer();\nawait renderer.init();\nrenderer.resetState();","handlingStrategy":"validation","validationCode":"await renderer.init();\nrenderer.resetState(); // safe now","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Await init before calling resetState.","Defer context-sharing reset logic until after init resolves.","Remember resetState is a no-op on WebGPU — confirm you need it.","Gate resetState behind an initialized flag in integrations."],"tags":["renderer","initialization","async","state-management","lifecycle"],"backgroundTag":null,"analyzedSha":"da05705fa31f02710c19772a2aa70c7454807f0c","analyzedAt":"2026-08-12T22:51:37.160Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}