godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
86.95k stars 19.48k forks source link

Export to Web fails from Windows (file in use and can't be overwritten) #65660

Closed Nuku closed 1 year ago

Nuku commented 1 year ago

Godot version

4.0 alpha 16

System information

Windows 11

Issue description

image All other exports work fine, but web produces this error each time. I've tried changing what directory it saves to, no difference.

Steps to reproduce

Export, add, Web, export project.

Minimal reproduction project

No response

Nuku commented 1 year ago

image Re-naming the tmp file it creates allows it to be uploaded, but then this error is visible in the console of the resulting page.

GithubPrankster commented 1 year ago

I also have this same issue and can attest to @Nuku's fix working. Their following error is due to the environment not having SharedArrayBuffer defined which is required now for 4.0.

Calinou commented 1 year ago

Can you reproduce this if you export the project in a path without any spaces or special characters?

If so, please upload a minimal reproduction project to make this easier to troubleshoot.

Re-naming the tmp file it creates allows it to be uploaded, but then this error is visible in the console of the resulting page.

You need to use a web server that sends the correct headers: https://docs.godotengine.org/en/latest/tutorials/export/exporting_for_web.html#threads (Double-clicking an HTML file to run the HTML5 project will not work.)

Thisisntmatt commented 1 year ago

I experienced this and setting a custom html shell in the export settings will allow it to export. image

alfredbaudisch commented 1 year ago

image

akien-mga commented 1 year ago

But then with the Custom HTML Shell the application does not run:

That's not a bug, see https://github.com/godotengine/godot/issues/65660#issuecomment-1243088017

alfredbaudisch commented 1 year ago

But then with the Custom HTML Shell the application does not run:

That's not a bug, see #65660 (comment)

You need to use a web server that sends the correct headers

I'm using a web server.

Anyway I'll try from another setup and will update it here.

akien-mga commented 1 year ago

You need to use a web server that sends the correct headers: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Embedder-Policy#certain_features_depend_on_cross-origin_isolation

And on a secure context.

alfredbaudisch commented 1 year ago

Yes, I have everything set accordingly already (the correct headers, SSL, etc). I'll try to test on Itch to see how it reacts.

alfredbaudisch commented 1 year ago

@akien-mga on Itch.io, with both SharedArrayBuffer support on or off, I got the error:

image

Thisisntmatt commented 1 year ago

@alfredbaudisch I got it to work on my webserver by setting the correct cors headers(I used Node.js): return res.sendFile(path.join(__dirname + '/public' + '/Web8' + req.url)), res.setHeader("Cross-Origin-Opener-Policy", "same-origin"), res.setHeader("Cross-Origin-Embedder-Policy", "require-corp") ; I guess mostly work, animated textures all come out pink, but that's a different issue for a different thread

nisovin commented 1 year ago

@akien-mga on Itch.io, with both SharedArrayBuffer support on or off, I got the error:

Itch.io's support for this feature currently only works in Chrome, and I think that looks like Firefox.

Nuku commented 1 year ago

Using chrome, but not on Itch.io https://flexiblesurvival.com/resources/FI/play.html

On Thu, Sep 15, 2022 at 3:36 PM Justin @.***> wrote:

@akien-mga https://github.com/akien-mga on Itch.io, with both SharedArrayBuffer support on or off, I got the error:

Itch.io's support for this feature currently only works in Chrome, and I think that looks like Firefox.

— Reply to this email directly, view it on GitHub https://github.com/godotengine/godot/issues/65660#issuecomment-1248708221, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGYPSJHZ45WS4F5PIN4RSLV6OQF5ANCNFSM6AAAAAAQJ26DQI . You are receiving this because you were mentioned.Message ID: @.***>

alfredbaudisch commented 1 year ago

@nisovin @Thisisntmatt @Nuku I confirm that on Chrome it works both in my local server and Itch.

vkbsb commented 1 year ago

Created PR https://github.com/godotengine/godot/pull/65881 for fixing the locked file issue. The output file was opened for read and then for write. The instance opened for write is closed before the one opened for read. This causes the _close() on the instance opened for write to fail.

Deins commented 1 year ago

Got it working for myself, but bumped into few issues on the way. Here are my tips for those who want to run it with current alpha:

  1. set custom http export shell line like mentioned above (to workaround the file locking issue). If the build errors the .tmp or other files won't work.
  2. use webserver and set correct headers like people said. I used nginx I set mine:
            add_header Cross-Origin-Opener-Policy same-origin;
            add_header Cross-Origin-Embedder-Policy require-corp; 
  3. Also your webserver has to serve the files as https. Might depend on browser, not sure, but it seemed that with plain http I got the same SharedArray error .
  4. first experiment from scratch with empty project. Otherwise you might get errors until you figure out what feature breaks it. For me I had enabled in project settings 'multithreaded renderer' which didn't work. And sky shader with clouds also didn't run.

here is sample, so you can test your browsers: https://www.deins.lv/godot_test/

Nuku commented 1 year ago

image Did that, new fancy error.

nisovin commented 1 year ago

@Nuku That's the original posted error, caused by the failed rename.

Deins commented 1 year ago

I got that error only when trying to use .tmp http shell. Did you do clean build with:

I experienced this and setting a custom html shell in the export settings will allow it to export. image

Nuku commented 1 year ago

What do you set the custom shell to?

Deins commented 1 year ago

image

Zireael07 commented 1 year ago

I see things need to be documented better...

tripodsan commented 1 year ago

here is sample, so you can test your browsers: https://www.deins.lv/godot_test/

on macos, running in:

Spycemyster commented 1 year ago

Might be related to this issue, but this is from a web export for a web game I'm developing (using Google Firebase as a backend) image

I've used the custom shell described above and I'm on Godot 4 beta 2.

Calinou commented 1 year ago

Might be related to this issue, but this is from a web export for a web game I'm developing (using Google Firebase as a backend) image

I've used the custom shell described above and I'm on Godot 4 beta 2.

This is not a bug. You need to host the project files on a web host that sends the correct headers as described in the Exporting for the Web documentation.

Spycemyster commented 1 year ago

Might be related to this issue, but this is from a web export for a web game I'm developing (using Google Firebase as a backend) image I've used the custom shell described above and I'm on Godot 4 beta 2.

This is not a bug. You need to host the project files on a web host that sends the correct headers as described in the Exporting for the Web documentation.

Ah I see, my mistake! I forgot to add the headers to my firebase.json file. I'll post what I have for posterity's sake in case anyone has the same problem as I did:

  "hosting": {
    "public": "public",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "headers": [ {
        "source" : "**",
        "headers" : [
            {
            "key" : "Access-Control-Allow-Origin",
            "value" : "*"
            },
            {
                "key" : "Cross-Origin-Opener-Policy",
                "value" : "same-origin"
            },
            {
                "key" : "Cross-Origin-Embedder-Policy",
                "value" : "require-corp"
            }
        ]
    }],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  },

Deploying to Firebase hosting using that as my firebase.json file fixed it.

Nuku commented 1 year ago

What should you put in the custom section?

On Wed, Sep 14, 2022, 3:50 PM Thisisntmatt @.***> wrote:

I experienced this and setting a custom html shell in the export settings will allow it to export. [image: image] https://user-images.githubusercontent.com/87195335/190276557-38d47412-8cf7-42e8-89f9-664a8864cfbb.png

— Reply to this email directly, view it on GitHub https://github.com/godotengine/godot/issues/65660#issuecomment-1247379192, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGYPSOX6DTE4T7VF55KI6LV6JJFHANCNFSM6AAAAAAQJ26DQI . You are receiving this because you were mentioned.Message ID: @.***>

sanchitgulati commented 1 year ago

If anyone is wondering how to do this on apache24 server.

<IfModule mod_headers.c>
  <Directory />
    Header always set Cross-Origin-Opener-Policy "same-origin"  
    Header always set Cross-Origin-Embedder-Policy "require-corp"  
  </Directory>  
</IfModule>  
netAction commented 1 year ago

For .htaccess, you can use this:

<IfModule mod_headers.c>
  Header always set Cross-Origin-Opener-Policy "same-origin"  
  Header always set Cross-Origin-Embedder-Policy "require-corp"  
</IfModule>
AwokeKnowing commented 9 months ago

As a long-time developer I think this path of Godot 4 for the web is problemmatic. I realize it's the browsers coming up with all these security policies but projects generally can be set up to run with no webserver modification provided that all the content is self-contained.

It seems Godot will end up having to create a docker container and be deployed basically with integrated webserver. In other words, I think rather than trying to convince people to add headers to webservers, people expecting an index.html file to 'just work' probably want:

  1. a bash script to make it work in web locally or on server
  2. a docker container that runs locally and can be just put on server/aws
  3. powershell script same as the bash script but for windows.
  4. the interface of godot should do this for you initially.

Now, once they have it running, they may investigate and find oh, i can do this myself with just a couple headers. But the problem is that when you're working in godot and just click export to web, you expect it to basically just work since it's for web and you have a browser.

At least, this message is not nearly as helpful as those familiar with the problem imagine: Error The following features required to run Godot projects on the Web are missing: Cross Origin Isolation - Check web server configuration (send correct headers) SharedArrayBuffer - Check web server configuration (send correct headers)

most people who know some web development don't really know about shared array buffers and obscure Spectre mitigation headers.

So you would at least have to give a user friendly message saying like:

Godot 4 uses advanced browser features which are only available if your server sends the following headers on the response for the HTML file:
Cross-Origin-Opener-Policy "same-origin"
Cross-Origin-Embedder-Policy "require-corp"

To set up a preconfigured webserver to run godot 4 projects in the browser, click here.  For deployment to a webserver however, you will need to make sure the two headers are sent back when this html file is requested.

I can' guarantee you that 99% of people exporting to web, even literal game developers would not just know what to do from the current message. They would end up frustrated and digging through docs and forums, when they expected it to just run in the browser, like a normal self-contained html5 app.

Having godot 4 apps showing up all over the web is going to be huge. so it seems worthy of streamlining.

and by the way, one application of godot 4 is in education. at my company I made this application: https://designer.knowledgecity.com (desktop only) and one thing I would like to do is include godot based templates for some of the educational activities.

But my post really is not about 'commercial' of pro scenarios when you can take the time to understand the headers etc. It's more about the indie experience where it is very disappointing that you export to web but it doesn't work do to special server settings which HTML/js front end developers almost never deal with.

Calinou commented 9 months ago

This is off-topic for the issue originally reported here.

As a long-time developer I think this path of Godot 4 for the web is problemmatic. I realize it's the browsers coming up with all these security policies but projects generally can be set up to run with no webserver modification provided that all the content is self-contained.

This can be worked around without any specific web server configuration. See https://github.com/godotengine/godot-proposals/issues/6616.

AwokeKnowing commented 9 months ago

Thanks. I added it here because here was where I found the 'solution' so i wasn't aware of anywhere else it was being worked on. at time i didn't realize it was closed, so i was just about to delete it and post as separate issue.

In any case, I'm glad you responded with the link to the correct place to discuss since I have a feeling some people will pass through this way until the workaround becomes automatic.