-
-
Notifications
You must be signed in to change notification settings - Fork 68
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
Use an HTML-based solution to the SharedArrayBuffers problem #6616
Comments
Even if this isn't the accepted approach for integration into the engine, I could see this being something very useful to add to the documentation as a stop gap solution. |
This doesn't entirely resolve the discoverability issue, but I've packaged this Javascript library into a plugin, which makes it pretty easy to use: |
For the record, work around this limitation in CI (say GitHub Actions or GitLab CI/CD): https://github.com/itsas-taldea/moon/blob/e4c1d959e6e54ef94c1152e9b9daab62ba3611a1/.github/workflows/Pipeline.yml#L107-L112 # Workaround for SharedArrayBuffer support on GitHub Pages
# See: https://github.com/godotengine/godot-docs/issues/7084
- run: |
cd public/play
curl -fsSL https://github.com/gzuidhof/coi-serviceworker/raw/master/coi-serviceworker.js > coi-serviceworker.js
sed -i 's#\( <script src="index.js"></script>\)# <script src="coi-serviceworker.js"></script>\n\1#g' index.html Have a test in https://itsas-taldea.github.io/moon/play/ |
enables cross origin isolation on the server running the web export without setting server headers (e.g. github pages) see godotengine/godot-proposals#6616 for more informations
I believe this solution can only affect the page with the game. Sites like itch use an iframe, and I believe the containing page also needs some special headers, which this solution cannot provide. |
To me keeping such an important feature as web exports on iframes, which is the main way web games get consumed online, locked because of multi-threading, which is a feature seldom used, is not right. I would much rather have lower performance due to single-threading than not being able to make my game be played. I'm with Juan on this one. |
Describe the project you are working on
Any web project
Describe the problem or limitation you are having in your project
Currently, a Godot 4 web build requires adding the following headers to an HTML page:
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp
This is necessary to unlock SharedArrayBuffers in compliant browsers. SharedArrayBuffers is in turn, necessary for threading.
This is problematic in more than one way:
Juan expressed wanting to restore single threads in the Godot codebase, but I see this as less than ideal for the following reasons:
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Instead, I suggest adding the MIT-licensed Coi-Service to the HTML template.
This worker-based solution works in the browsers I've tested it in and restores a one-click-export solution to Godot without needing single threads.
The price to pay is an initial reload of the page (as soon as the worker loads, it reloads the entire page). This is usually fast enough not to be noticeable on an average connection. Still, we could work around it with some UX (show an initial 1s loading screen before flashing to the load bar).
If implementing single-threaded Godot was still desirable for other reasons, this fix is easily revertable once single threads are here: remove one line in the HTML template and one javascript file.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
<script src="coi-serviceworker.min.js"></script>
to full-size.htmlMaybe add the license if the mention in the minified file isn't sufficient
If this enhancement will not be used often, can it be worked around with a few lines of script?
Anyone can add their template, that is not the issue. It's trivial to do (as demonstrated by the above paragraph).
Is there a reason why this should be core and not an add-on in the asset library?
Despite the fix being easy, many devs lack the experience to make sense of the error or how to work around it.
Even many experienced devs who aren't used to web similarly can't make sense of it.
An alternative to my suggestion would be a public announcement, with a fixed template (but unfortunately that would lack the nice large-scale testing that a feature can bring)
The text was updated successfully, but these errors were encountered: