{"record":{"id":"0fd9a3c3cf66fbd4","repo":"egametang/ET","slug":"invalid-magic","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.Dynamic/Io/VoxelFileReader.cs","lineNumber":45,"sourceCode":"    {\n        private readonly IRcCompressor _compressor;\n\n        public VoxelFileReader(IRcCompressor compressor)\n        {\n            _compressor = compressor;\n        }\n\n        public VoxelFile Read(BinaryReader stream)\n        {\n            RcByteBuffer buf = IOUtils.ToByteBuffer(stream);\n            VoxelFile file = new VoxelFile();\n            int magic = buf.GetInt();\n            if (magic != VoxelFile.MAGIC)\n            {\n                magic = IOUtils.SwapEndianness(magic);\n                if (magic != VoxelFile.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            file.version = buf.GetInt();\n            bool isExportedFromAstar = (file.version & VoxelFile.VERSION_EXPORTER_MASK) == 0;\n            bool compression = (file.version & VoxelFile.VERSION_COMPRESSION_MASK) == VoxelFile.VERSION_COMPRESSION_LZ4;\n            file.walkableRadius = buf.GetFloat();\n            file.walkableHeight = buf.GetFloat();\n            file.walkableClimb = buf.GetFloat();\n            file.walkableSlopeAngle = buf.GetFloat();\n            file.cellSize = buf.GetFloat();\n            file.maxSimplificationError = buf.GetFloat();\n            file.maxEdgeLen = buf.GetFloat();\n            file.minRegionArea = (int)buf.GetFloat();\n            if (!isExportedFromAstar)\n            {","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.recast/Scripts/Core/Share/Detour.Dynamic/Io/VoxelFileReader.cs#L27-L63","documentation":"VoxelFileReader.Read validates the first 4 bytes (magic number) of a voxel file against VoxelFile.MAGIC, trying both endianness. If neither matches, the stream is not a valid DotRecast/Detour voxel file. This guards against feeding corrupt or foreign-format data to the dynamic navmesh voxel loader.","triggerScenarios":"Opening a file that is not a voxel file at all (e.g. a navmesh .bin, a text file, a truncated file); a voxel file from an incompatible DotRecast/recast4j version with a different magic; a file whose header was overwritten/corrupted.","commonSituations":"Wrong file path passed to the reader; cached voxel file from an older library version; file download/copy was interrupted leaving a partial/corrupt header.","solutions":["Confirm the file was produced by VoxelFileWriter (DotRecast) and the path is correct.","Regenerate the voxel file with the current library version to clear format/version mismatch.","Verify file integrity (size, hash) before reading; handle IOException and re-export on failure."],"exampleFix":"// before\nvar file = new VoxelFileReader(compressor).Read(new BinaryReader(File.OpenRead(path)));\n\n// after — guard format\nusing var fs = File.OpenRead(path);\nusing var br = new BinaryReader(fs);\ntry { return new VoxelFileReader(compressor).Read(br); }\ncatch (IOException) { Log.Error($\"{path} is not a valid voxel file, regenerating\"); return Regenerate(path); }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { return new VoxelFileReader(compressor).Read(br); }\ncatch (IOException) { Log.Error($\"{path} is not a valid voxel file\"); return Regenerate(path); }","preventionTips":["Verify the file path and that it was written by VoxelFileWriter.","Regenerate voxel files after library version upgrades.","Check file size/hash integrity before reading."],"tags":["recast","detour-dynamic","voxel","serialization","data-integrity"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}