fix(viewer): await renderer.init() in Canvas gl factory (#233)
The WebGPURenderer needs its backend initialized before any direct `.render(scene, camera)` call. The commented-out `// renderer.init()` said "Only use when using <DebugRenderer />", but the non-debug path also calls direct render from the post-processing fallback (post-processing.tsx:318), which throws "Renderer: .render() called before the backend is initialized" on any browser that falls back to the WebGL2 backend. Switching the gl factory to an async function and awaiting init() before returning is safe in both backends (init() is idempotent and the async factory is a supported @react-three/fiber v9+ pattern), and prevents the error in WebGL2 fallback.
This commit is contained in:
@@ -110,6 +110,12 @@ const Viewer: React.FC<ViewerProps> = ({
|
||||
const renderer = new THREE.WebGPURenderer(props as any)
|
||||
renderer.toneMapping = THREE.ACESFilmicToneMapping
|
||||
renderer.toneMappingExposure = 0.9
|
||||
// Awaiting init() is required when the browser falls back to the
|
||||
// WebGL2 backend (Safari without the WebGPU flag, older Chrome on
|
||||
// machines without a WebGPU device). In native WebGPU mode the
|
||||
// init resolves almost instantly. Without this await, the first
|
||||
// render throws "Renderer: .render() called before the backend is
|
||||
// initialized" from the post-processing fallback path.
|
||||
await renderer.init()
|
||||
return renderer
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user