{"record":{"id":"049ff0d6f4f14f17","repo":"babalae/better-genshin-impact","slug":"error-049ff0","errorCode":null,"errorMessage":"未能返回主界面","messagePattern":"未能返回主界面","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/GameTask/Common/Job/SwitchPartyTask.cs","lineNumber":47,"sourceCode":"    public async Task<bool> Start(string partyName, CancellationToken ct)\n    {\n        bool isInPartyViewUi = false;\n\n        Logger.LogInformation(\"尝试切换至队伍: {Name}\", partyName);\n        using var ra1 = CaptureToRectArea();\n\n        if (!Bv.IsInPartyViewUi(ra1))\n        {\n            isInPartyViewUi = true;\n            // 如果不在主界面，则返回主界面\n            if (!Bv.IsInMainUi(ra1))\n            {\n                await _returnMainUiTask.Start(ct);\n                await Delay(200, ct);\n                using var raAfterMain = CaptureToRectArea();\n                if (!Bv.IsInMainUi(raAfterMain))\n                {\n                    throw new InvalidOperationException(\"未能返回主界面\");\n                }\n            }\n\n            // 尝试打开队伍配置页面\n            const int maxAttempts = 2;\n            bool isOpened = false;\n            for (int attempt = 1; attempt <= maxAttempts; attempt++)\n            {\n                Simulation.SendInput.SimulateAction(GIActions.OpenPartySetupScreen);\n\n                // 考虑加载时间 2s，共检查 4.2s，如果失败则抛出异常\n\n                for (int i = 0; i < 7; i++) // 检查 7 次\n                {\n                    await Delay(600, ct);\n                    using var raCheck = CaptureToRectArea();\n                    if (Bv.IsInPartyViewUi(raCheck))\n                    {","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/GameTask/Common/Job/SwitchPartyTask.cs#L29-L65","documentation":"In SwitchPartyTask.Start, when not already on the party-view UI and not on the main UI, it runs _returnMainUiTask.Start then re-checks Bv.IsInMainUi. If still not on the main UI it throws InvalidOperationException — the prerequisite for opening the party screen is missing.","triggerScenarios":"Bv.IsInPartyViewUi false AND Bv.IsInMainUi false initially; after _returnMainUiTask.Start(ct) + Delay(200), a fresh capture still fails Bv.IsInMainUi.","commonSituations":"The game is stuck on a loading screen, a cutscene, an unescapable dialog, or a domain; ReturnMainUiTask could not escape the current screen; capture is stale; a game version changed the main-UI detection markers Bv.IsInMainUi relies on.","solutions":["Make sure the game is in an ESCAPABLE state (open world, not in a cutscene/domain) before calling SwitchPartyTask.Start.","Verify Bv.IsInMainUi detectors match the current game version.","Increase the Delay(200) after ReturnMainUiTask or retry the return once before giving up.","If the screen is genuinely stuck, the user must manually return to the main UI first."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (!Bv.IsInMainUi(CaptureToRectArea()))\n{\n    await _returnMainUiTask.Start(ct);\n    if (!Bv.IsInMainUi(CaptureToRectArea()))\n        throw new InvalidOperationException(\"游戏未处于可打开队伍界面的主界面状态\");\n}","typeGuard":null,"tryCatchPattern":"try { await partyTask.Start(partyName, ct); }\ncatch (InvalidOperationException ex) when (ex.Message == \"未能返回主界面\")\n{ _logger.LogError(ex, \"无法返回主界面：游戏可能处于过场/秘境，请手动回到主界面\"); }","preventionTips":["Call SwitchPartyTask only from an escapable open-world state.","Keep Bv.IsInMainUi detectors current with the game version.","Retry the return-to-main-UI once before aborting."],"tags":["party-setup","ui-automation","main-ui","navigation","switch-party"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}