{"record":{"id":"64d22e43be272d08","repo":"babalae/better-genshin-impact","slug":"error-64d22e","errorCode":null,"errorMessage":"不在主界面，无法识别小地图坐标","messagePattern":"不在主界面，无法识别小地图坐标","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Core/Script/Dependence/Genshin.cs","lineNumber":267,"sourceCode":"\n    /// <summary>\n    /// 获取当前在小地图上的位置坐标，如果缓存时间内有匹配成功的坐标优先返回缓存坐标，否则调用NavigationInstance的getPositionStable\n    /// </summary>\n    /// <param name=\"mapName\">大地图名称</param>\n    /// <param name=\"cacheTimeMs\">缓存时间，单位毫秒，默认900ms</param>\n    /// <returns>包含X和Y坐标的Point2f结构体</returns>\n    public Point2f? GetPositionFromMap(string mapName, int cacheTimeMs = 900)\n    {\n        var matchingMethod = TaskContext.Instance().Config.PathingConditionConfig.MapMatchingMethod;\n        return GetPositionFromMapWithMatchingMethod(mapName,matchingMethod, cacheTimeMs);\n    }\n    \n    public Point2f? GetPositionFromMapWithMatchingMethod(string mapName, string matchingMethod, int cacheTimeMs = 900)\n    {\n        using var imageRegion = CaptureToRectArea();\n        if (!Bv.IsInMainUi(imageRegion))\n        {\n            throw new InvalidOperationException(\"不在主界面，无法识别小地图坐标\");\n        }\n        return MapManager.GetMap(mapName, matchingMethod)\n            .ConvertImageCoordinatesToGenshinMapCoordinates(LazyNavigationInstance.Value\n                .GetPositionStableByCache(imageRegion, mapName, matchingMethod, cacheTimeMs));\n    }\n    \n    /// <summary>\n    /// 获取当前在小地图上的位置坐标, 局部匹配, 需要世界坐标, 在坐标附近匹配, 失败不进行全局匹配\n    /// </summary>\n    /// <param name=\"mapName\">大地图名称</param>\n    /// <param name=\"x\">世界坐标x</param>\n    /// <param name=\"y\">世界坐标y</param>\n    /// <returns>包含X和Y坐标的Point2f结构体</returns>\n    public Point2f? GetPositionFromMap(string mapName, float x, float y)\n    {\n        using var imageRegion = CaptureToRectArea();\n        if (!Bv.IsInMainUi(imageRegion))\n        {","sourceCodeStart":249,"sourceCodeEnd":285,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Core/Script/Dependence/Genshin.cs#L249-L285","documentation":"Thrown by GetPositionFromMapWithMatchingMethod when the game screen is not on the main overworld UI (GameUiCategory.Main). The method captures the game window and runs Bv.IsInMainUi, which image-matches for the minimap area and main-UI UI elements. Since minimap-based coordinate recognition only works when the minimap is visible, any other screen state (menu, dialogue, loading, big map, pause) is a hard failure.","triggerScenarios":"Calling genshin.GetPositionFromMap(mapName) or GetPositionFromMapWithMatchingMethod(mapName, matchingMethod) while the game shows a non-overworld screen: Paimon menu (Esc), character screen, inventory, dialogue, loading screen, big map (M), or any domain/abyss interior that hides the standard minimap.","commonSituations":"Script calls GetPositionFromMap immediately after a teleport or scene transition before the loading screen finishes. Script left the game in a menu state (e.g. after SetTime without returning to main UI). Game window not focused or capture returning a stale/black frame.","solutions":["Call ReturnMainUi or press Esc to close any open menu before invoking GetPositionFromMap.","Add a delay after teleport or loading-screen transitions to ensure the main UI has fully rendered.","Call Bv.IsInMainUi (or Bv.WhichGameUi) yourself before GetPositionFromMap and skip or wait if false.","Wrap the call in try/catch(InvalidOperationException) and implement a retry loop with a bounded delay."],"exampleFix":"// before\ngenshin.GetPositionFromMap(\"Teyvat\");\n\n// after\nif (Bv.IsInMainUi(TaskContext.Instance().CaptureToRectAreaUsingAtLeastOnce()))\n{\n    genshin.GetPositionFromMap(\"Teyvat\");\n}\nelse\n{\n    await new ReturnMainUiTask().Start(CancellationContext.Instance.Cts.Token);\n    genshin.GetPositionFromMap(\"Teyvat\");\n}","handlingStrategy":"validation","validationCode":"// Validate game UI state before calling GetPositionFromMap\nusing var region = TaskContext.Instance().CaptureToRectAreaUsingAtLeastOnce();\nif (!Bv.IsInMainUi(region))\n{\n    // return to main UI first\n    await new ReturnMainUiTask().Start(CancellationContext.Instance.Cts.Token);\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    var pos = genshin.GetPositionFromMap(mapName);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"不在主界面\"))\n{\n    // game not on main UI — return to main UI and retry once\n    await new ReturnMainUiTask().Start(CancellationContext.Instance.Cts.Token);\n    await Task.Delay(2000);\n    pos = genshin.GetPositionFromMap(mapName);\n}","preventionTips":["Always return to main UI before position-detection calls.","Add a post-teleport delay to allow loading screens to clear.","Use Bv.WhichGameUi() to detect and handle different UI states proactively."],"tags":["game-state","image-recognition","minimap","precondition"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}