{"record":{"id":"45b53d99544bdc39","repo":"egametang/ET","slug":"invalid-magic-45b53d","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/Io/DtMeshDataReader.cs","lineNumber":61,"sourceCode":"        }\n\n        public DtMeshData Read32Bit(RcByteBuffer buf, int maxVertPerPoly)\n        {\n            return Read(buf, maxVertPerPoly, true);\n        }\n\n        public DtMeshData Read(RcByteBuffer buf, int maxVertPerPoly, bool is32Bit)\n        {\n            DtMeshData data = new DtMeshData();\n            DtMeshHeader header = new DtMeshHeader();\n            data.header = header;\n            header.magic = buf.GetInt();\n            if (header.magic != DtMeshHeader.DT_NAVMESH_MAGIC)\n            {\n                header.magic = IOUtils.SwapEndianness(header.magic);\n                if (header.magic != DtMeshHeader.DT_NAVMESH_MAGIC)\n                {\n                    throw new IOException(\"Invalid magic\");\n                }\n\n                buf.Order(buf.Order() == RcByteOrder.BIG_ENDIAN ? RcByteOrder.LITTLE_ENDIAN : RcByteOrder.BIG_ENDIAN);\n            }\n\n            header.version = buf.GetInt();\n            if (header.version != DtMeshHeader.DT_NAVMESH_VERSION)\n            {\n                if (header.version < DtMeshHeader.DT_NAVMESH_VERSION_RECAST4J_FIRST\n                    || header.version > DtMeshHeader.DT_NAVMESH_VERSION_RECAST4J_LAST)\n                {\n                    throw new IOException(\"Invalid version \" + header.version);\n                }\n            }\n\n            bool cCompatibility = header.version == DtMeshHeader.DT_NAVMESH_VERSION;\n            header.x = buf.GetInt();\n            header.y = buf.GetInt();","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.recast/Scripts/Core/Share/Detour/Io/DtMeshDataReader.cs#L43-L79","documentation":"Thrown by DtMeshDataReader.Read when the first int of the byte buffer is not the Detour navmesh magic (DT_NAVMESH_MAGIC), even after a trial endianness swap. The magic identifies a valid single-tile navmesh data blob; its absence means the input is not a Detour tile mesh, is truncated, or is a different file type.","triggerScenarios":"Loading a file that is a navmesh set (.navmesh) through the single-tile reader; passing a raw OBJ/geometry buffer; a truncated or zero-padded file; endianness from an unsupported source.","commonSituations":"Pointing the reader at a whole-set file instead of a tile file; corrupt download/asset; reading an asset produced by an incompatible toolchain.","solutions":["Use DtMeshSetReader for whole navmesh set files and DtMeshDataReader only for individual tile blobs.","Verify the file is non-empty and begins with the expected 4-byte magic before reading.","Re-export the navmesh data with a supported tool (DotRecast/recast) and confirm it loads round-trip.","Check asset import/pipeline for truncation or re-encoding."],"exampleFix":"// before\nvar data = meshDataReader.Read(buf, maxVertPerPoly, is32Bit); // wrong file\n\n// after\n// pick reader by file kind\nvar mesh = setReader.Read(buf);","handlingStrategy":"validation","validationCode":"// Peek the first 4 bytes before handing the buffer to the reader.\nint magic = BitConverter.ToInt32(chunk, 0);\nif (magic != DtMeshHeader.DT_NAVMESH_MAGIC &&\n    IOUtils.SwapEndianness(magic) != DtMeshHeader.DT_NAVMESH_MAGIC)\n    throw new InvalidDataException(\"Not a Detour tile mesh\");","typeGuard":"static bool IsDetourTileMagic(int m)\n    => m == DtMeshHeader.DT_NAVMESH_MAGIC || IOUtils.SwapEndianness(m) == DtMeshHeader.DT_NAVMESH_MAGIC;","tryCatchPattern":"try { var data = meshDataReader.Read(buf, nvp, is32Bit); }\ncatch (IOException e) when (e.Message.Contains(\"Invalid magic\"))\n{ /* try set reader, or reject file */ }","preventionTips":["Match the reader to the file kind (single tile vs set).","Validate the magic bytes before reading.","Re-export corrupt assets from source.","Confirm the asset pipeline does not truncate or re-encode files."],"tags":["detour","io","serialization","magic","file-format"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}