Description
The WebGL and WebGPU backends have code which expect()
s success in obtaining a canvas:
Lines 956 to 959 in 94ce763
Lines 36 to 41 in 94ce763
These will panic if the browser declines to provide a context, which may happen for reasons outside of the application programmer's control (browser does not support WebGPU or WebGL2, insufficient GPU memory, browser glitches) as well as ones which are (such as trying to use the same canvas for "2d"
drawing). Therefore, the application may have reason to handle the error (if nothing else, to give the user an error message visible on the web page), which is best done by returning an Err
rather than panicking — especially as Rust on wasm32
does not support unwinding, so every panic is fatal to the Rust module and can at best be handled from JavaScript.
This is not a solely theoretical scenario — I noticed the problem due to some Bevy Jam #2 games failing to start.
Platform
web, wgpu 0.13