isaac-mason / recast-navigation-js

JavaScript navigation mesh construction, path-finding, and spatial reasoning toolkit. WebAssembly port of Recast Navigation.
https://recast-navigation-js.isaacmason.com
MIT License
266 stars 24 forks source link

tiled navmesh generation Fails #162

Closed yelouafi closed 6 months ago

yelouafi commented 1 year ago

Drop this file on https://navmesh.isaacmason.com/

Case 1: Generate a tiled mesh with cell size 0.1 and tileSize: 32

Navmesh generation fails with Aborted() error

Also seems the lib isn't recovering, retrying with other params always gives Aborted after the first error.

Case 2: reload, drop the file and generate with 0.2 cell size

The navmesh bounds do not cover the whole input meshes

Screenshot 2023-09-25 at 19 07 09

Also noticed the non recovery issue happens whenever the generation fails (for example after solo generation fails for big scenes, retrying with different params seems to fail instantly)

isaac-mason commented 1 year ago

Thanks again for the repros! I'll do some investigation soon and get back to you.

isaac-mason commented 1 year ago

Both of these issues appear to be memory related.

For this larger model, it looks like the cell size and tile sizes can be increased a fair bit without sacrificing much precision, which would at least mitigate these issues as nav mesh generation would require much less memory.

Digging into the causes though -


Re case 1: the failure here is emscripten reaching it's currently configured max memory limit - 2gb.

Here's a relevant log from a debug build:

Cannot enlarge memory, asked to go up to 2147487744 bytes, but the limit is 2147483648 bytes!

I've got a couple of WIP changes to help with this.

First, I've got a fix that will lower the max memory usage for generateTiledNavMesh and generateTileCache when keepIntermediates is false. Right now tile intermediates for nav mesh generation are only released after processing all tiles or on failure. I'll change this so they are released after processing each tile. You can track that here: https://github.com/isaac-mason/recast-navigation-js/issues/163

Second, I'm adding a "keep intermediates" checkbox to the navmesh generator website that can be unchecked when attempting to generate navmeshes for large models.

I can also look into whether this limit can be raised, but consuming 2gb of memory in a browser is unideal šŸ˜… I'm also not sure whether the heap can be shrunk, that needs looking into.


Re case 2: after some number of tiles are processed and added to the nav mesh, navMesh.addTile starts failing with an error code for failing to allocate memory.

This one I still need to do some more investigation on. It doesn't look like emscripten's wasm heap is reaching 2gb, so maybe the error is misleading and has a different meaning.

isaac-mason commented 1 year ago

Also seems the lib isn't recovering, retrying with other params always gives Aborted after the first error.

I'll also look into this šŸ™‚

yelouafi commented 1 year ago

Thanks! Yeah I think I can get good results and also faster gen time with 0.5. Although Iā€™m sticking to solo navmesh right now since I noted some navigation issues with tiles (most likely related to the pruning issue)

isaac-mason commented 1 year ago

Noted! I'm going to spend some time improving the debugging tools (https://github.com/isaac-mason/recast-navigation-js/issues/165), and after this I'll circle back here hopefully better equipped.

Samsy commented 8 months ago

Hello there !

Having the exact same issue with the tiling

isaac-mason commented 8 months ago

Hey @Samsy, if you can share your model and code I'm happy to take a look šŸ™‚