babalae/better-genshin-impact · error · PartySetupFailedException

切换角色:角色列表关闭后未返回队伍配置页

Error message

切换角色:角色列表关闭后未返回队伍配置页

What it means

After the card-recognition loop, RecognizeTeamSlotsFromCharacterList presses ESCAPE to close the list and waits up to 10x300ms for IsPartyConfigPage to confirm the party-config page returned. If the list did not close back to party config, the snapshot flow is aborted because the next steps assume party-config context.

Source

Thrown at BetterGenshinImpact/GameTask/Common/Job/SwitchCharacterStateMachineTask.cs:1439

                    characterNames.Add(candidate.Score >= MatchThreshold ? candidate.CharacterName : null);
                }

                break;
            }
        }
        finally
        {
            Simulation.SendInput.Keyboard.KeyPress(Vanara.PInvoke.User32.VK.VK_ESCAPE);
        }

        var returned = await NewRetry.WaitForAction(() =>
        {
            using var capture = CaptureToRectArea();
            return IsPartyConfigPage(capture);
        }, ct, 10, 300);
        if (!returned)
        {
            throw new PartySetupFailedException("切换角色:角色列表关闭后未返回队伍配置页");
        }

        if (characterNames.Count != expectedTeamCount || characterNames.Any(string.IsNullOrEmpty))
        {
            throw new PartySetupFailedException(
                $"切换角色:角色列表队伍识别不完整,期望 {expectedTeamCount} 个," +
                $"末次检测到 {lastDetectedCardCount} 张卡片,成功识别 {characterNames.Count(name => name != null)} 个头像");
        }

        var result = characterNames
            .Select((name, index) => new TeamSlotSnapshot(index + 1, name))
            .ToList();
        _logger.LogDebug(
            "切换角色:当前账号可控角色 {ControlCount} 个,生成 {SnapshotCount} 项队伍快照,映射 {SlotMapping}",
            _maxControlAvatarCount,
            result.Count,
            string.Join(",", _logicalToPhysicalSlot
                .OrderBy(pair => pair.Key)

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Confirm IsPartyConfigPage's detector (title text/ROI) still matches the current party-config layout.
  2. Ensure ESCAPE input is reaching the game (check Simulation.SendInput focus) — re-send if needed.
  3. Increase the 10x300ms budget if the close animation is slow.
  4. If the list closes to main UI, re-open party config before retrying recognition.
Defensive patterns

Strategy: retry

Try / catch

try { await switchTask.Start(...); }
catch (PartySetupFailedException ex) when (ex.Message.Contains("未返回队伍配置页"))
{ _logger.LogWarning(ex, "角色列表关闭后未回到队伍配置页,建议重试"); }

Prevention

When it happens

Trigger: NewRetry.WaitForAction(() => IsPartyConfigPage(capture)) returns false after 10 attempts following the VK_ESCAPE keypress in the finally block.

Common situations: ESCAPE did not register (input focus elsewhere, game busy); the list closed to a different screen (e.g. main UI) instead of party config; IsPartyConfigPage detector text/ROI changed in a game update; a transition animation exceeded the budget.

Related errors


AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13). Data as JSON: /api/errors/f76302973b054afd. Report an issue: GitHub.