{"record":{"id":"01847ace1f1f34c4","repo":"egametang/ET","slug":"e-message","errorCode":null,"errorMessage":"{e.Message}","messagePattern":"\\{e\\.Message\\}","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Packages/cn.etetet.recast/Scripts/Core/Share/Detour.TileCache/DtTileCacheBuilder.cs","lineNumber":1931,"sourceCode":"            try\n            {\n                hw.Write(bw, layer.header, order, cCompatibility);\n                int gridSize = layer.header.width * layer.header.height;\n                byte[] buffer = new byte[gridSize * 3];\n                for (int i = 0; i < gridSize; i++)\n                {\n                    buffer[i] = (byte)layer.heights[i];\n                    buffer[gridSize + i] = (byte)layer.areas[i];\n                    buffer[gridSize * 2 + i] = (byte)layer.cons[i];\n                }\n\n                var compressed = comp.Compress(buffer);\n                bw.Write(compressed);\n                return ms.ToArray();\n            }\n            catch (IOException e)\n            {\n                throw new Exception(e.Message, e);\n            }\n        }\n\n        public byte[] CompressTileCacheLayer(DtTileCacheLayerHeader header, int[] heights, int[] areas, int[] cons, RcByteOrder order, bool cCompatibility, IRcCompressor comp)\n        {\n            using var ms = new MemoryStream();\n            using var bw = new BinaryWriter(ms);\n            DtTileCacheLayerHeaderWriter hw = new DtTileCacheLayerHeaderWriter();\n            try\n            {\n                hw.Write(bw, header, order, cCompatibility);\n                int gridSize = header.width * header.height;\n                byte[] buffer = new byte[gridSize * 3];\n                for (int i = 0; i < gridSize; i++)\n                {\n                    buffer[i] = (byte)heights[i];\n                    buffer[gridSize + i] = (byte)areas[i];\n                    buffer[gridSize * 2 + i] = (byte)cons[i];","sourceCodeStart":1913,"sourceCodeEnd":1949,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.recast/Scripts/Core/Share/Detour.TileCache/DtTileCacheBuilder.cs#L1913-L1949","documentation":"CompressTileCacheLayer wraps the underlying byte compression in a try/catch and rethrows any IOException as a generic Exception whose message is the original IOException's message (and chains it as inner). The thrown text is therefore the compressor/IO error verbatim, e.g. a buffer or stream failure from IRcCompressor.Compress. The real cause is an IO/compression failure during layer serialization.","triggerScenarios":"Calling CompressTileCacheLayer when IRcCompressor.Compress throws (bad buffer, unsupported format, or a custom compressor fault); writing to a MemoryStream that is closed/disposed.","commonSituations":"A custom IRcCompressor implementation raising IOException; malformed header (width*height producing wrong gridSize) feeding a too-small buffer; endianness/C-compat flag mismatch corrupting the stream mid-write.","solutions":["Inspect the chained InnerException (the original IOException) for the true cause.","Validate header.width*height and the heights/areas/cons array lengths equal gridSize before calling.","If using a custom IRcCompressor, ensure Compress never throws IOException on valid input."],"exampleFix":"// before\nbyte[] bytes = builder.CompressTileCacheLayer(header, heights, areas, cons, order, cCompat, comp);\n\n// after: validate inputs and surface the real cause\nint gridSize = header.width * header.height;\nif (heights.Length < gridSize || areas.Length < gridSize || cons.Length < gridSize)\n    throw new InvalidOperationException(\"layer arrays smaller than width*height\");\ntry { byte[] bytes = builder.CompressTileCacheLayer(header, heights, areas, cons, order, cCompat, comp); }\ncatch (Exception ex) { throw new InvalidOperationException(\"layer compress failed\", ex.InnerException ?? ex); }","handlingStrategy":"try-catch","validationCode":"int gridSize = header.width * header.height;\nif (heights.Length < gridSize || areas.Length < gridSize || cons.Length < gridSize)\n    throw new InvalidOperationException(\"layer arrays smaller than width*height\");\nbyte[] bytes = builder.CompressTileCacheLayer(header, heights, areas, cons, order, cCompat, comp);","typeGuard":null,"tryCatchPattern":"try { return builder.CompressTileCacheLayer(header, heights, areas, cons, order, cCompat, comp); }\ncatch (Exception e) { throw new InvalidDataException(\"layer compress failed\", e.InnerException ?? e); }","preventionTips":["Always inspect ex.InnerException for the real IOException.","Validate header.width*height against array lengths first.","Confirm IRcCompressor.Compress is robust on valid input."],"tags":["io","detour-tilecache","compression","wrapper"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}