{"record":{"id":"98b9e896baaf7097","repo":"egametang/ET","slug":"invalid-tile-index-98b9e8","errorCode":null,"errorMessage":"Invalid tile index","messagePattern":"Invalid tile index","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Packages/cn.etetet.recast/Scripts/Core/Share/Detour/DtNavMesh.cs","lineNumber":581,"sourceCode":"        /// @param[out] data Data associated with deleted tile.\n        /// @param[out] dataSize Size of the data associated with deleted tile.\n        ///\n        /// This function returns the data for the tile so that, if desired,\n        /// it can be added back to the navigation mesh at a later point.\n        ///\n        /// @see #addTile\n        public long RemoveTile(long refs)\n        {\n            if (refs == 0)\n            {\n                return 0;\n            }\n\n            int tileIndex = DecodePolyIdTile(refs);\n            int tileSalt = DecodePolyIdSalt(refs);\n            if (tileIndex >= m_maxTiles)\n            {\n                throw new Exception(\"Invalid tile index\");\n            }\n\n            DtMeshTile tile = m_tiles[tileIndex];\n            if (tile.salt != tileSalt)\n            {\n                throw new Exception(\"Invalid tile salt\");\n            }\n\n            // Remove tile from hash lookup.\n            GetTileListByPos(tile.data.header.x, tile.data.header.y).Remove(tile);\n\n            // Remove connections to neighbour tiles.\n            // Create connections with neighbour tiles.\n\n            // Disconnect from other layers in current tile.\n            List<DtMeshTile> nneis = GetTilesAt(tile.data.header.x, tile.data.header.y);\n            foreach (DtMeshTile j in nneis)\n            {","sourceCodeStart":563,"sourceCodeEnd":599,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.recast/Scripts/Core/Share/Detour/DtNavMesh.cs#L563-L599","documentation":"Thrown by DtNavMesh.RemoveTile after decoding the tile index from the supplied refs. If the decoded index is >= m_maxTiles, the reference cannot correspond to any slot in the m_tiles array, so it is rejected as out of range. This almost always means refs is corrupted, truncated, or belongs to a different navmesh configuration.","triggerScenarios":"Calling RemoveTile(refs) with a refs value from another DtNavMesh built with a different m_maxTiles; passing a half-overwritten long; using a poly ref where a tile ref is expected; reusing a refs after rebuilding the navmesh with a different tile capacity.","commonSituations":"Persisting refs across sessions where the navmesh was rebuilt with different tile counts; mixing up polygon refs and tile refs; corrupting the handle during serialization.","solutions":["Only call RemoveTile with a refs returned by AddTile on the same DtNavMesh instance.","Rebuild or re-query the tile ref after any navmesh reconstruction and discard old handles.","Guard the call by decoding the index and comparing against m_maxTiles before invoking RemoveTile.","Audit serialization paths for truncation of the 64-bit refs value."],"exampleFix":"// before\nmesh.RemoveTile(refsFromAnotherMesh);\n\n// after\nint idx = DtNavMesh.DecodePolyIdTile(refs);\nif (idx < mesh.GetMaxTiles())\n    mesh.RemoveTile(refs);\nelse\n    Debug.LogWarning(\"Ignoring stale/cross-mesh tile ref\");","handlingStrategy":"validation","validationCode":"int idx = DtNavMesh.DecodePolyIdTile(refs);\nif (idx >= mesh.GetMaxTiles() || refs == 0)\n    return; // ignore out-of-range/stale ref\nmesh.RemoveTile(refs);","typeGuard":"static bool IsPlausibleTileRef(DtNavMesh mesh, long refs)\n    => refs != 0 && DtNavMesh.DecodePolyIdTile(refs) < mesh.GetMaxTiles();","tryCatchPattern":"try { mesh.RemoveTile(refs); }\ncatch (Exception e) when (e.Message.Contains(\"Invalid tile index\"))\n{ Debug.LogWarning($\"Ignored out-of-range tile ref {refs}\"); }","preventionTips":["Always obtain refs from AddTile on the same mesh instance.","Discard persisted refs after rebuilding the navmesh.","Decode and range-check the index before calling RemoveTile.","Serialize refs as full 64-bit values; guard against truncation."],"tags":["detour","navmesh","tile","stale-handle","serialization"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}