babalae/better-genshin-impact · error · Exception

识别骰子数量不正确,重试超时,停止自动打牌!

Error message

识别骰子数量不正确,重试超时,停止自动打牌!

What it means

Thrown by GeniusInvokationControl.ReRollDice when RollPhaseReRoll returns false for more than 35 consecutive retries (each with a 500ms sleep, totaling ~17.5s). RollPhaseReRoll performs OCR dice recognition during the reroll phase; if it consistently fails to recognize the correct dice layout, the abort guard fires.

Source

Thrown at BetterGenshinImpact/GameTask/AutoGeniusInvokation/GeniusInvokationControl.cs:552

        _logger.LogInformation("保留{Msg}骰子", msg);
        Sleep(5000);
        var retryCount = 0;
        // 保留 x、万能 骰子
        while (!RollPhaseReRoll(holdElementalTypes))
        {
            retryCount++;

            if (IsDuelEnd())
            {
                throw new NormalEndException("对战已结束,停止自动打牌!");
            }

            //MyLogger.Debug("识别骰子数量不正确,第{}次重试中...", retryCount);
            Sleep(500);
            if (retryCount > 35)
            {
                throw new System.Exception("识别骰子数量不正确,重试超时,停止自动打牌!");
            }
        }

        ClickConfirm();
        _logger.LogInformation("选择需要重投的骰子后点击确认完毕");

        Sleep(1000);
        // 鼠标移动到中心
        ClickGameWindowCenter();

        _logger.LogInformation("等待5s对方重投");
        Sleep(5000);
    }

    public Point MakeOffset(Point p)
    {
        var rect = TaskContext.Instance().SystemInfo.CaptureAreaRect;
        return new Point(rect.X + p.X, rect.Y + p.Y);

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Ensure the game runs at a supported resolution (typically 1920x1080) in windowed or borderless mode.
  2. Close overlays (RTSS, Discord overlay, etc.) that may cover the dice area.
  3. Verify the capture region is correctly set to the game window.
  4. Check that the game is fully in focus and the reroll phase UI is fully rendered before the script starts.
  5. If the issue persists, it may indicate dice recognition templates need updating after a game patch.
Defensive patterns

Strategy: try-catch

Try / catch

// Wrap the TCG task in a top-level try-catch to handle OCR failures gracefully
try
{
    control.ReRollDice(holdTypes);
}
catch (Exception e) when (e.Message.Contains("识别骰子数量不正确"))
{
    _logger.LogError("骰子识别失败,停止自动打牌: {Msg}", e.Message);
    // Notify user to check resolution, game focus, and overlays
}

Prevention

When it happens

Trigger: During the TCG dice reroll phase, the screen capture + OCR pipeline consistently returns an invalid dice count or layout. The duel is checked for IsDuelEnd between retries, but after 35 failures the method gives up. Root causes: resolution mismatch, UI遮挡 (overlay covering dice), game not fully rendered, or OCR template failure.

Common situations: Game running at unsupported resolution, dice area partially obscured by another window or overlay, game not in focus, capture region misconfigured, or game UI changed after an update breaking dice recognition templates. Slow GPU rendering can cause the dice animation to not have settled within the retry window.

Related errors


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