Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGPURenderer causes warning: render() called before the backend is initialized #3403

Closed
verekia opened this issue Nov 26, 2024 · 3 comments
Assignees

Comments

@verekia
Copy link
Contributor

verekia commented Nov 26, 2024

R3F v8 and v9 both cause the following warning:
THREE.Renderer: .render() called before the backend is initialized. Try using .renderAsync() instead.

Reproduction:

@krispya
Copy link
Member

krispya commented Dec 6, 2024

@CodyJasonBennett provided a workaround here:

  const [frameloop, setFrameloop] = useState('never')

  return (
    <Canvas
      frameloop={frameloop}
      gl={canvas => {
        const renderer = new WebGPURenderer({
          canvas,
          powerPreference: 'high-performance',
          antialias: true,
          alpha: true,
        })
        renderer.init().then(() => setFrameloop('always'))
        renderer.xr = { addEventListener: () => {} }
        return renderer
      }}
    >

But ideally we leverage suspense and allow for a promise to be passed into gl such that this works:

<Canvas 
  gl={async (canvas) => {
    const renderer = new WebGPURenderer({
      canvas,
      powerPreference: 'high-performance',
      antialias: true,
      alpha: true,
    });

    await renderer.init();
    // This shouldn't be necessary either
    // renderer.xr = { addEventListener: () => {} };
    return renderer;
  }}
>

@krispya krispya self-assigned this Dec 6, 2024
@CodyJasonBennett
Copy link
Member

The fix here would be to prefer renderAsync over render when able, but I'm not comfortable acting until three has a more stable API here.

@verekia
Copy link
Contributor Author

verekia commented Feb 1, 2025

Since 9.0.0-rc.2 we can do this:

<Canvas
  gl={async (glProps) => {
    const renderer = new WebGPURenderer(glProps)
    await renderer.init()
    return renderer
  }}
>

The frameloop state workaround is no longer necessary.

@verekia verekia closed this as completed Feb 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants