{"record":{"id":"99c0edc0bb190ece","repo":"babalae/better-genshin-impact","slug":"error-99c0ed","errorCode":null,"errorMessage":"当前不在主界面","messagePattern":"当前不在主界面","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/GameTask/AutoTrackPath/AutoTrackPathTask.cs","lineNumber":210,"sourceCode":"                // Debug.WriteLine($\"当前人物图像坐标系角度：{angle}\");\n\n                // var moveAngle = (int)(_targetAngle - angle);\n                // Debug.WriteLine($\"旋转到目标角度：{_targetAngle}，鼠标平移{moveAngle}单位\");\n                // Simulation.SendInput.Mouse.MoveMouseBy(moveAngle, 0);\n                Sleep(60);\n            }\n        });\n    }\n\n    public Task Track(List<GiPathPoint> pList, int angleOffsetUnit, CancellationTokenSource trackCts)\n    {\n        return new Task(() =>\n        {\n            var currIndex = 0;\n            while (!_ct.IsCancellationRequested)\n            {\n                var ra = CaptureToRectArea();\n                var miniMapMat = GetMiniMapMat(ra) ?? throw new InvalidOperationException(\"当前不在主界面\");\n\n                // 注意游戏坐标系的角度是顺时针的\n                var matchingMethod = TaskContext.Instance().Config.PathingConditionConfig.MapMatchingMethod;\n                var currMapImageAvatarPos = MapManager.GetMap(MapTypes.Teyvat, matchingMethod).GetMiniMapPosition(miniMapMat);\n                if (currMapImageAvatarPos.IsEmpty())\n                {\n                    Debug.WriteLine(\"识别小地图位置失败\");\n                    continue;\n                }\n                var (nextMapImagePathPoint, nextPointIndex) = GetNextPoint(currMapImageAvatarPos, pList, currIndex); // 动态计算下个点位\n                var nextMapImagePathPos = nextMapImagePathPoint.MatchPt;\n                Logger.LogInformation(\"下个点位[{Index}]：{nextMapImagePathPos}\", nextPointIndex, nextMapImagePathPos);\n\n                var angle = CharacterOrientation.Compute(miniMapMat);\n                CameraOrientation.DrawDirection(ra, angle, \"avatar\", new Pen(Color.Blue, 1));\n                Debug.WriteLine($\"当前人物图像坐标系角度：{angle}，位置：{currMapImageAvatarPos}\");\n\n                var nextAngle = Math.Round(Math.Atan2(nextMapImagePathPos.Y - currMapImageAvatarPos.Y, nextMapImagePathPos.X - currMapImageAvatarPos.X) * 180 / Math.PI);","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/GameTask/AutoTrackPath/AutoTrackPathTask.cs#L192-L228","documentation":"InvalidOperationException in AutoTrackPathTask.Track's main loop when GetMiniMapMat returns null on the first capture of the iteration. GetMiniMapMat returns null when ElementRecognition cannot find the PaimonMenu element (top-left Paimon face icon), which is the standard sentinel for 'currently on the main in-world UI'. Absence means the game is in a menu/dialogue/loading screen.","triggerScenarios":"Track loop iterating while the player opened the inventory/map/menu, entered dialogue, hit a loading screen, or the PaimonMenu template failed to match due to resolution/HDR/capture desync. Because the Track loop has no retry around this first GetMiniMapMat, the first missed frame aborts tracking.","commonSituations":"User interacted with the game mid-track; cutscene triggered; capture pipeline delivered a stale/blank frame; resolution mismatch broke PaimonMenu template; PaimonMenu hidden by a notification toast at that instant.","solutions":["Do not interact with the game during an active AutoTrackPath run.","Run at 1920x1080 so the PaimonMenu template matches reliably.","Treat this as abort: re-run the path from a teleport point after returning to the main UI.","If frequent, wrap the GetMiniMapMat call in a short retry before throwing so a single bad frame does not abort."],"exampleFix":"// before\nvar miniMapMat = GetMiniMapMat(ra) ?? throw new InvalidOperationException(\"当前不在主界面\");\n\n// after: tolerate a few transient misses\nvar miniMapMat = GetMiniMapMat(ra);\nif (miniMapMat == null)\n{\n    Logger.LogDebug(\"未检测到主界面，跳过本帧\");\n    Sleep(100);\n    continue;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await trackTask; }\ncatch (InvalidOperationException e) when (e.Message == \"当前不在主界面\")\n{ /* return to main UI and restart the route from nearest TP */ }","preventionTips":["Do not interact with the game during AutoTrackPath runs.","Run at 1920x1080 so the PaimonMenu template matches every frame.","Wrap the first GetMiniMapMat in a short retry instead of throwing on a single miss."],"tags":["auto-track","minimap","ui-state","paimon-menu","cv"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}