{"record":{"id":"bcd627559f4382c0","repo":"babalae/better-genshin-impact","slug":"layerid-bcd627","errorCode":null,"errorMessage":"灰度分层地图 {LayerId} 读取失败","messagePattern":"灰度分层地图 (.+?) 读取失败","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"BetterGenshinImpact/GameTask/Common/Map/Maps/Base/BaseMapLayerByTemplateMatch.cs","lineNumber":42,"sourceCode":"    public float Top { get; set; } = 0;\n    public float Left { get; set; } = 0;\n    public bool IsOverSize  { get; set; } = false;\n    [JsonIgnore]\n    public required FastSqDiffMatcher CoarseColorMatcher; // 小尺寸彩图\n    [JsonIgnore]\n    public Mat FineGrayMap = new Mat(); // 大尺寸灰度图\n    \n    public void LoadLayer(string layerDir)\n    {\n        SpeedTimer speedTimer = new($\"加载 {LayerId} 地图图片\");\n        var colorMapFileName = LayerId + \"_color\" + \".webp\";\n        var colorMapPath = Path.Combine(layerDir, colorMapFileName);\n        var coarseColorMap = Bv.ImRead(colorMapPath)?? throw new Exception($\"彩色分层地图 {LayerId} 读取失败\");\n        speedTimer.Record(\"精确匹配用彩图\");\n        CoarseColorMatcher = new FastSqDiffMatcher(coarseColorMap, new Size(52, 52));\n        var grayMapFileName = LayerId + \"_gray\" + (IsOverSize ? \".png\" : \".webp\");\n        var grayMapPath = Path.Combine(layerDir, grayMapFileName);\n        FineGrayMap = Bv.ImRead(grayMapPath, ImreadModes.Grayscale)?? throw new Exception($\"灰度分层地图 {LayerId} 读取失败\");\n        speedTimer.Record(\"粗匹配用灰度图\");\n        speedTimer.DebugPrint();\n    }\n\n    public static List<BaseMapLayerByTemplateMatch> LoadLayers(SceneBaseMapByTemplateMatch sceneBaseMap)\n    {\n        var layers = new List<BaseMapLayerByTemplateMatch>();\n        var layerDir = Path.Combine(Global.Absolute(@\"Assets\\Map\\\"), sceneBaseMap.Type.ToString());\n        if (!Directory.Exists(layerDir))\n        {\n            return layers;\n        }\n        var jsonFiles = Directory.GetFiles(layerDir, \"*.json\", SearchOption.AllDirectories);\n        foreach (var jsonFile in jsonFiles)\n        {\n            var json = File.ReadAllText(jsonFile);\n            var tempLayers = JsonSerializer.Deserialize<List<BaseMapLayerByTemplateMatch>>(json) ?? throw new Exception(\"Failed to deserialize JSON.\");\n            layers.AddRange(tempLayers);","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/GameTask/Common/Map/Maps/Base/BaseMapLayerByTemplateMatch.cs#L24-L60","documentation":"Companion to error 406, thrown when reading the gray map image for a template-match layer. Same caveat: Bv.ImRead is non-nullable, so the '?? throw' is unreachable; the actual failure for a missing <LayerId>_gray.webp (or .png when IsOverSize) is a FileNotFoundException from File.OpenRead inside ImRead, not this custom exception.","triggerScenarios":"LoadLayer computes grayMapPath = Path.Combine(layerDir, LayerId + \"_gray\" + (IsOverSize ? \".png\" : \".webp\")) and calls Bv.ImRead(grayMapPath, ImreadModes.Grayscale). Missing file → File.OpenRead throws before this message could ever be reached.","commonSituations":"IsOverSize flag in the JSON is true but only a .webp (not .png) gray map exists, or vice versa; LayerId mismatch; partial asset deployment.","solutions":["Confirm <LayerId>_gray.webp (or <LayerId>_gray.png when IsOverSize=true) exists for each layer.","Ensure the IsOverSize flag in the JSON matches which gray-image extension is shipped.","Guard with File.Exists(grayMapPath) before ImRead so the intended error message is actually produced."],"exampleFix":"// before\nFineGrayMap = Bv.ImRead(grayMapPath, ImreadModes.Grayscale)?? throw new Exception($\"灰度分层地图 {LayerId} 读取失败\");\n\n// after\nif (!File.Exists(grayMapPath)) throw new Exception($\"灰度分层地图 {LayerId} 读取失败: 缺少 {grayMapPath}\");\nFineGrayMap = Bv.ImRead(grayMapPath, ImreadModes.Grayscale);","handlingStrategy":"validation","validationCode":"var grayMapPath = Path.Combine(layerDir, LayerId + \"_gray\" + (IsOverSize ? \".png\" : \".webp\"));\nif (!File.Exists(grayMapPath)) throw new FileNotFoundException($\"缺少灰度地图: {grayMapPath}\", grayMapPath);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure IsOverSize in JSON matches the shipped gray-image extension.","Validate all referenced image paths exist at startup."],"tags":["map-data","asset-loading","missing-file","template-match","dead-code"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}