babalae/better-genshin-impact · error · Exception

游戏窗口分辨率不是 16:9

Error message

游戏窗口分辨率不是 16:9

What it means

LogScreenResolution 用 SystemControl.GetGameScreenRect 取游戏窗口尺寸,校验 Width:Height == 16:9(Width*9 == Height*16),不满足即 LogError 后抛 Exception。自动首领讨伐的坐标/OCR 假设 16:9 画布,非该比例会导致所有缩放坐标错位。

Source

Thrown at BetterGenshinImpact/GameTask/AutoBoss/AutoBossTask.cs:1064

        yield return $"{bossName}前往.json";

        if (AutoBossData.IsTalkToStartBoss(bossName))
        {
            yield return $"{bossName}战斗后快速前往.json";
        }
    }

    /// <summary>
    /// 校验当前游戏窗口是否满足自动首领讨伐所需的 16:9 分辨率。
    /// </summary>
    /// <exception cref="Exception">游戏窗口不是 16:9 时抛出。</exception>
    private void LogScreenResolution()
    {
        var gameScreenSize = SystemControl.GetGameScreenRect(TaskContext.Instance().GameHandle);
        if (gameScreenSize.Width * 9 != gameScreenSize.Height * 16)
        {
            _logger.LogError("游戏窗口分辨率不是 16:9 !当前分辨率为 {Width}x{Height}", gameScreenSize.Width, gameScreenSize.Height);
            throw new Exception("游戏窗口分辨率不是 16:9");
        }

        if (gameScreenSize.Width < 1920 || gameScreenSize.Height < 1080)
        {
            Logger.LogWarning("游戏窗口分辨率小于 1920x1080 !当前分辨率为 {Width}x{Height} , 小于 1920x1080 的分辨率的游戏可能无法正常使用自动首领功能 !",
                gameScreenSize.Width, gameScreenSize.Height);
        }
    }

    /// <summary>
    /// 回到主界面并按配置尝试切换到指定队伍。
    /// </summary>
    private async Task Prepare()
    {
        await _returnMainUiTask.Start(_ct);

        if (string.IsNullOrWhiteSpace(_taskParam.TeamName))
        {

View on GitHub (pinned to a7cb36712d)

Solutions

  1. 将游戏设为 16:9 分辨率(如 1920×1080、1280×720)。
  2. 确保窗口未被拉伸(使用原生或全屏 16:9)。
  3. 关闭系统 DPI 缩放对游戏的影响,或确认 GetGameScreenRect 返回物理像素。
  4. 确认 TaskContext 中 GameHandle 指向正确的游戏窗口。
Defensive patterns

Strategy: validation

Validate before calling

var size = SystemControl.GetGameScreenRect(TaskContext.Instance().GameHandle);
bool is169 = size.Width * 9 == size.Height * 16;
// UI 启动前预检并提示用户调整分辨率

Prevention

When it happens

Trigger: 游戏窗口设为非 16:9 分辨率(如 1920×1200、2560×1080 之外的异形比例、窗口被拉伸);获取到的句柄不是游戏主窗口;多显示器 DPI 缩放导致尺寸异常。

Common situations: 用户改了游戏分辨率;窗口模式拉伸;DPI 缩放使 GetGameScreenRect 返回逻辑尺寸不符;后台/多开场景句柄错误。

Related errors


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