{"record":{"id":"7792b3ca9b417a27","repo":"BabylonJS/Babylon.js","slug":"unable-to-deserialize-tilecache","errorCode":null,"errorMessage":"Unable to deserialize TileCache.","messagePattern":"Unable to deserialize TileCache\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/addons/src/navigation/generator/generator.common.ts","lineNumber":39,"sourceCode":"    return {\n        navMesh: result.navMesh,\n        navMeshQuery: new recast.NavMeshQuery(result.navMesh),\n        tileCache: undefined,\n    };\n}\n\n/**\n * Builds a TileCache and NavMeshQuery from serialized data.\n * @param data The serialized TileCache data.\n * @param tileCacheMeshProcess Optional function to process the TileCache mesh.\n * @returns An object containing the TileCache, NavMesh, and NavMeshQuery.\n */\nexport function BuildFromTileCacheData(data: Uint8Array, tileCacheMeshProcess: TileCacheMeshProcess) {\n    const recast = GetRecast();\n    const result = recast.importTileCache(data, tileCacheMeshProcess);\n\n    if (!result.tileCache) {\n        throw new Error(`Unable to deserialize TileCache.`);\n    }\n\n    return {\n        navMesh: result.navMesh,\n        navMeshQuery: new recast.NavMeshQuery(result.navMesh),\n        tileCache: result.tileCache,\n    };\n}\n","sourceCodeStart":21,"sourceCodeEnd":48,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/addons/src/navigation/generator/generator.common.ts#L21-L48","documentation":"BuildFromTileCacheData deserializes a tiled navmesh cache via Recast's importTileCache, which needs both the bytes and a TileCacheMeshProcess callback. It throws when the import returns no tileCache, meaning the WASM library could not parse the data as a tile cache — corrupt, truncated, or version-incompatible bytes.","triggerScenarios":"Calling BuildFromTileCacheData(data, tileCacheMeshProcess) with bytes that aren't a valid serialized tile cache (empty array, wrong asset, truncated download) or that were written by an incompatible Recast version/build.","commonSituations":"Loading tiled navmesh data saved by a different tool or library version; network transfer corruption; accidentally passing a monolithic navmesh dump (for BuildFromNavmeshData) instead of tile-cache data.","solutions":["Verify the serialized tile cache bytes (size, provenance) and that they were produced by `serialize` on the matching recast-navigation-js version.","Confirm you are calling the right builder — use BuildFromNavmeshData for monolithic navmeshes and this function only for tile-cache data.","Wrap in try/catch and regenerate the tile cache from geometry at load time as a fallback."],"exampleFix":"// before\nconst nav = BuildFromTileCacheData(unknownBytes, meshProcess); // wrong data kind -> throws\n// after\nif (isTileCacheData(unknownBytes)) { // e.g. check magic header/size saved at export\n  const nav = BuildFromTileCacheData(unknownBytes, meshProcess);\n} else {\n  const nav = BuildFromNavmeshData(unknownBytes);\n}","handlingStrategy":"validation","validationCode":"const res = await fetch(tileCacheUrl);\nif (!res.ok) throw new Error(`tilecache fetch failed: ${res.status}`);\nconst data = new Uint8Array(await res.arrayBuffer());\nif (data.byteLength === 0) throw new Error(\"tilecache data empty\");\nconst nav = BuildFromTileCacheData(data, tileCacheMeshProcess);","typeGuard":"const isPlausibleTileCacheData = (d: Uint8Array): boolean => d.byteLength > 0;","tryCatchPattern":"try {\n  nav = BuildFromTileCacheData(data, meshProcess);\n} catch (e) {\n  if (String(e).includes(\"Unable to deserialize TileCache\")) {\n    nav = rebuildTileCacheFromGeometry(meshProcess);\n  } else throw e;\n}","preventionTips":["Distinguish serialized tile-cache vs monolithic navmesh files and load each with the matching builder.","Store a format/version header with tile cache exports and validate before import.","Always supply a valid TileCacheMeshProcess callback when importing."],"tags":["navigation","recast","deserialization","tilecache","corrupt-data"],"backgroundTag":"deserialization-failed","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}