{"record":{"id":"f9e2c0fbdde433f0","repo":"egametang/ET","slug":"invalid-magic-f9e2c0","errorCode":null,"errorMessage":"Invalid magic","messagePattern":"Invalid magic","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"Packages/cn.etetet.recast/Scripts/Core/Share/Detour.TileCache/Io/DtTileCacheReader.cs","lineNumber":53,"sourceCode":"            _compFactory = compFactory;\n        }\n\n        public DtTileCache Read(BinaryReader @is, int maxVertPerPoly, IDtTileCacheMeshProcess meshProcessor)\n        {\n            RcByteBuffer bb = IOUtils.ToByteBuffer(@is);\n            return Read(bb, maxVertPerPoly, meshProcessor);\n        }\n\n        public DtTileCache Read(RcByteBuffer bb, int maxVertPerPoly, IDtTileCacheMeshProcess meshProcessor)\n        {\n            DtTileCacheSetHeader header = new DtTileCacheSetHeader();\n            header.magic = bb.GetInt();\n            if (header.magic != DtTileCacheSetHeader.TILECACHESET_MAGIC)\n            {\n                header.magic = IOUtils.SwapEndianness(header.magic);\n                if (header.magic != DtTileCacheSetHeader.TILECACHESET_MAGIC)\n                {\n                    throw new IOException(\"Invalid magic\");\n                }\n\n                bb.Order(bb.Order() == RcByteOrder.BIG_ENDIAN ? RcByteOrder.LITTLE_ENDIAN : RcByteOrder.BIG_ENDIAN);\n            }\n\n            header.version = bb.GetInt();\n            if (header.version != DtTileCacheSetHeader.TILECACHESET_VERSION)\n            {\n                if (header.version != DtTileCacheSetHeader.TILECACHESET_VERSION_RECAST4J)\n                {\n                    throw new IOException(\"Invalid version\");\n                }\n            }\n\n            bool cCompatibility = header.version == DtTileCacheSetHeader.TILECACHESET_VERSION;\n            header.numTiles = bb.GetInt();\n            header.meshParams = paramReader.Read(bb);\n            header.cacheParams = ReadCacheParams(bb, cCompatibility);","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.recast/Scripts/Core/Share/Detour.TileCache/Io/DtTileCacheReader.cs#L35-L71","documentation":"DtTileCacheReader.Read parses a tile-cache *set* file. The first int must be TILECACHESET_MAGIC ('T','S','E','T' = 0x54534554); if it fails the reader tries byte-swapping once and re-checks, throwing only if both fail. So this error means the bytes are not a tile-cache set in either endianness.","triggerScenarios":"Calling DtTileCacheReader.Read on a file that isn't a tile-cache set (e.g. a raw navmesh, a single layer, or unrelated bytes); a truncated/corrupt header where even the swapped int isn't the magic.","commonSituations":"Loading the wrong asset (navmesh .bin mistaken for a tile-cache set); corrupt download; feeding a single layer blob to the set reader.","solutions":["Verify the file is a tile-cache set produced by DtTileCacheWriter (magic 'TSET').","Check the file is not truncated or corrupted (compare length/hash against the baked asset).","Ensure you are calling the set reader (DtTileCacheReader) only on full tile-cache set files, not individual layers or navmesh tiles."],"exampleFix":"// before: feeding the wrong blob\nusing var fs = File.OpenRead(path); // might be a navmesh, not a tilecache set\nvar tc = reader.Read(bb, maxVertPerPoly, proc);\n\n// after: confirm magic before handing off\nint magic = bb.GetInt();\nif (magic != DtTileCacheSetHeader.TILECACHESET_MAGIC\n && IOUtils.SwapEndianness(magic) != DtTileCacheSetHeader.TILECACHESET_MAGIC)\n    throw new InvalidDataException(\"not a tile-cache set file\");\nbb.RewindInt();\nvar tc = reader.Read(bb, maxVertPerPoly, proc);","handlingStrategy":"validation","validationCode":"int magic = bb.GetInt();\nif (magic != DtTileCacheSetHeader.TILECACHESET_MAGIC\n && IOUtils.SwapEndianness(magic) != DtTileCacheSetHeader.TILECACHESET_MAGIC)\n    throw new InvalidDataException(\"not a tile-cache set file (bad magic)\");","typeGuard":null,"tryCatchPattern":"try { return reader.Read(bb, maxVertPerPoly, proc); }\ncatch (IOException e) when (e.Message == \"Invalid magic\")\n{ /* file is not a tile-cache set; do not retry unchanged */ }","preventionTips":["Only pass full tile-cache set files (magic 'TSET') to DtTileCacheReader.","Verify file integrity (length/hash) before loading.","Do not feed single layers or navmesh tiles to the set reader."],"tags":["io","detour-tilecache","serialization","magic"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}