You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
allsey87 opened this issue
Feb 26, 2024
· 2 comments
· Fixed by #12134
Labels
A-AssetsLoad files from disk to use for things like images, models, and soundsC-BugAn unexpected or incorrect behaviorO-WebSpecific to web (WASM) builds
Ran Bevy in a Web Worker with an OffscreenCanvas and routed events over postMessage.
What went wrong
Everything was working nicely until I had to fetch a GLTF asset and I kept getting a panic. Turns out that HttpWasmAssetReader::fetch_bytes from bevy_asset assumes at wasm.rs#41 that it is running in a window and not in a worker.
Note that gloo-net used to have a similar issue but resolved the issue by probing the global object to see whether it was a web_sys::Window or a web_sys::WorkerGlobalScope in request.rs#323.
Additional information
This issue could be resolved by either adding a dependency on gloo-net or duplicating its logic into bevy_asset. For the latter approach, it might also be an idea to then add an option field to the HttpWasmAssetReader that contains the probed global object type once it has been "resolved".
The text was updated successfully, but these errors were encountered:
@mockersf I think it would be nice to have a standalone web worker example but I also think it needs to be discussed first since there are various approaches that can be taken.
# Objective
This PR fixes#12125
## Solution
The logic in this PR was borrowed from gloo-net and essentially probes
the global Javascript context to see if we are in a window or a worker
before calling `fetch_with_str`.
---------
Co-authored-by: Zachary Harrold <zac@harrold.com.au>
# Objective
This PR fixes#12125
## Solution
The logic in this PR was borrowed from gloo-net and essentially probes
the global Javascript context to see if we are in a window or a worker
before calling `fetch_with_str`.
---------
Co-authored-by: Zachary Harrold <zac@harrold.com.au>
A-AssetsLoad files from disk to use for things like images, models, and soundsC-BugAn unexpected or incorrect behaviorO-WebSpecific to web (WASM) builds
Bevy version
0.13
Relevant system information
WebAssembly/Web Worker
What you did
Ran Bevy in a Web Worker with an OffscreenCanvas and routed events over postMessage.
What went wrong
Everything was working nicely until I had to fetch a GLTF asset and I kept getting a panic. Turns out that
HttpWasmAssetReader::fetch_bytes
frombevy_asset
assumes at wasm.rs#41 that it is running in a window and not in a worker.Note that gloo-net used to have a similar issue but resolved the issue by probing the global object to see whether it was a
web_sys::Window
or aweb_sys::WorkerGlobalScope
in request.rs#323.Additional information
This issue could be resolved by either adding a dependency on gloo-net or duplicating its logic into bevy_asset. For the latter approach, it might also be an idea to then add an option field to the
HttpWasmAssetReader
that contains the probed global object type once it has been "resolved".The text was updated successfully, but these errors were encountered: