donmccurdy / aframe-inspector-plugin-recast

A-Frame Inspector plugin for creating navigation meshes.
MIT License
65 stars 14 forks source link

CORS error / FUNCTION_PAYLOAD_TOO_LARGE for mesh > 5MB #25

Open diarmidmackenzie opened 3 years ago

diarmidmackenzie commented 3 years ago

Hi, trying to use this to create a navmesh, but I am hitting a CORS error:

Access to fetch at 'https://recast-api.donmccurdy.com/v1/build/?cellSize=0.3&cellHeight=0.2&agentHeight=1.6&agentRadius=0.2&agentMaxClimb=0.5&agentMaxSlope=30' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

This looks very similar to this issue, closed and fixed in January 2020: https://github.com/donmccurdy/aframe-inspector-plugin-recast/issues/14

Could it be a similar issue again?

donmccurdy commented 3 years ago

As far as I can tell the service is working normally, is this still happening for you?

It's possible that the CORS error is hiding some other server error, i.e. the processing on the scene failed. If you can share a demo with your A-Frame scene that may help to debug.

diarmidmackenzie commented 3 years ago

Hi, sorry for not getting back to you sooner. The scene I am working with is available here:

https://automatic-addition.surge.sh/nav-mesh.html

I have set up as per the instructions, and stripped out most of the rest of the page (just left in movement/teleport).

I enter the Inspector, then choose "Build" with the default settings. I get a pop-up: "Oops, something went wrong.", and when I look in the console I see the following:

Access to fetch at 'https://recast-api.donmccurdy.com/v1/build/?cellSize=0.3&cellHeight=0.2&agentHeight=1.6&agentRadius=0.2&agentMaxClimb=0.5&agentMaxSlope=30' from origin 'https://automatic-addition.surge.sh' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

donmccurdy commented 3 years ago

Inspecting the network tab a bit more, there's a FUNCTION_PAYLOAD_TOO_LARGE error coming back. It looks like my web host has a 5MB upload limit, which I don't think was there when I first started this service... your model's geometry seems to be just over that limit.

I'll leave this open as a bug - the service should at least report a clearer error when this is the problem.

The best workarounds would be to (a) use a simpler geometry for computing the navmesh, it doesn't have to be the same one that's rendered, or (b) to run the navmesh service locally as explained in https://github.com/donmccurdy/aframe-inspector-plugin-recast#tips-limits-and-performance.

jaydhulia commented 3 years ago

Hi @donmccurdy, I ran into this bug recently. I have tried to run it locally, but I am running into issues getting it working locally as well. I have the API running on localhost:3000 and can see the homepage. However, hitting "Build" on the plugin causes an error, and error stack on terminal is:

[1] Cannot find module './build/Release/RecastCLI.node'
[1] Require stack:
[1] - aframe-inspector-plugin-recast/node_modules/@donmccurdy/recast/index.js
[1] - aframe-inspector-plugin-recast/function.js
[1] - Library/Caches/com.vercel.cli/dev/builders/node_modules/@now/node/dist/launcher.js
[1] - Library/Caches/com.vercel.cli/dev/builders/node_modules/@now/node/dist/dev-server.js

Any ideas on what may be happening here?

jaydhulia commented 3 years ago

Update: was able to get it running locally, but facing a new error:

[1] 637365 vertices, 212455 faces.
[1] recast::load: 139.309ms
[1] Error! Failed to complete request to /v1/build/?cellSize=0.3&cellHeight=0.2&agentHeight=1.6&agentRadius=0.2&agentMaxClimb=0.5&agentMaxSlope=30: Error: socket hang up

The error in console is:

NO_RESPONSE_FROM_FUNCTION

Any ideas on what may be the cause for this? Doesn't happen for smaller GTLF files, so it seems that the bigger GLTF is causing a timeout. Is that something I can change somewhere :(

donmccurdy commented 3 years ago

Just to check, is the local demo making requests to a local Function, or to the remotely hosted one? This should be visible in the browser's Network tab.

The usual cause here is that my hosted version, subject to Vercel's free tier, has a 5mb I/O limit. If the scene has a lot of geometry, or just covers so much space that the navmesh becomes a large geometry, it can hit these limits. I wouldn't expect a local build to hit that constraint though...

jaydhulia commented 3 years ago

Hi @donmccurdy, Thank you for the reply! I ended up fixing the error! It was hitting the local API endpoint, however, for some reason, the socket was closing before the browser got any response with the error:

NO_RESPONSE_FROM_FUNCTION

It turns out it was because I was using a Node version that didn't work with this repo (14.X), once I switched to 10.X, it worked.

As a side note: the dependencies don't include now which is required to run the API server locally, so it would be nice to have that included for future folks who run this locally 😄

dotnetmaster commented 3 years ago

Hi, Thanks for such a great library, I have installed node v 10.0.0 and cloned the repository. Npm install works fine, I have installed now manually as suggested and I can call npm run dev and the server runs on port 9966 as far as I can see. But when I click on build button to build my nav mesh I gett following errors on my browser console: aframe-inspector-plugin-recast.js:8897 POST http://localhost:3000/v1/build/?cellSize=0.3&cellHeight=0.2&agentHeight=1.6&agentRadius=0.2&agentMaxClimb=0.5&agentMaxSlope=30 net::ERR_CONNECTION_REFUSED rebuild @ aframe-inspector-plugin-recast.js:8897 (anonymous) @ aframe-inspector-plugin-recast.js:8877 aframe-inspector-plugin-recast.js:8924 TypeError: Failed to fetch (anonymous) @ aframe-inspector-plugin-recast.js:8924 Promise.catch (async) rebuild @ aframe-inspector-plugin-recast.js:8923 (anonymous) @ aframe-inspector-plugin-recast.js:8877

I would appreciate if anyone could help. Alex

donmccurdy commented 3 years ago

The error above is coming from the client; there should (hopefully?) be a more informative error from the 'server' in your terminal showing what has gone wrong. At least in my case the local server runs on port 3000, you can test that running now dev alone.

dotnetmaster commented 3 years ago

Thanks for your prompt response mate. I had to install and configure now globally, I thought its just needs to be added to the project. Issue is now fixed and now I can generate my navmesh :-)