Skip to content

Commit

Permalink
feat: check whether the library has been initialised in the high leve…
Browse files Browse the repository at this point in the history
…l generators, throw a friendly error
  • Loading branch information
isaac-mason committed Jun 23, 2024
1 parent fea697b commit 1571a45
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/nervous-rabbits-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@recast-navigation/generators": patch
"recast-navigation": patch
---

feat: check whether the library has been initialised in the high level generators, throw a friendly error
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ export const generateSoloNavMesh = (
navMeshGeneratorConfig: Partial<SoloNavMeshGeneratorConfig> = {},
keepIntermediates = false
): SoloNavMeshGeneratorResult => {
if (!Raw.Module) {
throw new Error(
'"init" must be called before using any recast-navigation-js APIs. See: https://github.com/isaac-mason/recast-navigation-js?tab=readme-ov-file#initialization'
);
}

const buildContext = new RecastBuildContext();

const intermediates: SoloNavMeshGeneratorIntermediates = {
Expand Down Expand Up @@ -141,7 +147,7 @@ export const generateSoloNavMesh = (
error,
};
};

/* input geometry */
const vertices = positions as number[];
const numVertices = indices.length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ export const generateTileCache = (
navMeshGeneratorConfig: Partial<TileCacheGeneratorConfig> = {},
keepIntermediates = false
): TileCacheGeneratorResult => {
if (!Raw.Module) {
throw new Error(
'"init" must be called before using any recast-navigation-js APIs. See: https://github.com/isaac-mason/recast-navigation-js?tab=readme-ov-file#initialization'
);
}

const buildContext = new RecastBuildContext();

const intermediates: TileCacheGeneratorIntermediates = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ export const generateTiledNavMesh = (
navMeshGeneratorConfig: Partial<TiledNavMeshGeneratorConfig> = {},
keepIntermediates = false
): TiledNavMeshGeneratorResult => {
if (!Raw.Module) {
throw new Error(
'"init" must be called before using any recast-navigation-js APIs. See: https://github.com/isaac-mason/recast-navigation-js?tab=readme-ov-file#initialization'
);
}

const buildContext = new RecastBuildContext();

const intermediates: TiledNavMeshGeneratorIntermediates = {
Expand Down

0 comments on commit 1571a45

Please sign in to comment.