babalae/better-genshin-impact · error · InvalidOperationException

最终合成个数读取失败。

Error message

最终合成个数读取失败。

What it means

Thrown at the final verification step after the add/reduce fine-tuning loops when ReadCurrentCraftQuantity() again returns a non-positive value. The fine-tuning clicks (addButton 1614,672 / reduceButton 1074,672) are assumed to have landed, but the OCR field can no longer be read.

Source

Thrown at BetterGenshinImpact/GameTask/Common/Job/CraftMaterialTask.cs:442

        while (actualQuantity < targetQuantity)
        {
            GameCaptureRegion.GameRegion1080PPosClick(addButton.X, addButton.Y);
            await Delay(60, _ct);
            actualQuantity++;
        }

        while (actualQuantity > targetQuantity)
        {
            GameCaptureRegion.GameRegion1080PPosClick(reduceButton.X, reduceButton.Y);
            await Delay(60, _ct);
            actualQuantity--;
        }

        await Delay(200, _ct);
        var verifiedQuantity = ReadCurrentCraftQuantity();
        if (verifiedQuantity <= 0)
        {
            throw new InvalidOperationException("最终合成个数读取失败。");
        }

        if (verifiedQuantity != targetQuantity)
        {
            throw new InvalidOperationException($"最终合成个数与目标不一致,目标 {targetQuantity},当前 {verifiedQuantity}。");
        }

        return verifiedQuantity;
    }

    /// <summary>
    /// 读取右侧当前合成个数。
    /// </summary>
    /// <returns>识别到的当前合成个数;失败时返回 0。</returns>
    private int ReadCurrentCraftQuantity()
    {
        var text = StringUtils.ConvertFullWidthNumToHalfWidth(ReadOcrText(Rect1080(1248, 615, 221, 34)));
        return ReadFirstPositiveInt(text);

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Lengthen the Delay(200) before the final read so the quantity field fully re-renders after button clicks.
  2. Confirm the add/reduce button coordinates (1614,672 / 1074,672) still sit on the actual buttons at the current scale.
  3. Re-read once after a longer delay before throwing.
  4. Guard the fine-tune loops so a click that changes the UI is detected (e.g. re-check we are still on the craft panel).

Example fix

// before
await Delay(200, _ct);
var verifiedQuantity = ReadCurrentCraftQuantity();
if (verifiedQuantity <= 0)
{
    throw new InvalidOperationException("最终合成个数读取失败。");
}

// after: one longer-delay re-read
await Delay(200, _ct);
var verifiedQuantity = ReadCurrentCraftQuantity();
if (verifiedQuantity <= 0)
{
    await Delay(400, _ct);
    verifiedQuantity = ReadCurrentCraftQuantity();
}
if (verifiedQuantity <= 0)
{
    throw new InvalidOperationException("最终合成个数读取失败。");
}
Defensive patterns

Strategy: retry

Validate before calling

null

Type guard

null

Try / catch

try { await SetCraftQuantity(target); }
catch (InvalidOperationException e) when (e.Message.Contains("最终合成个数读取失败"))
{ /* re-capture after a longer delay and re-read */ }

Prevention

When it happens

Trigger: After the while-loops that click add/reduce buttons, ReadCurrentCraftQuantity() on Rect1080(1248,615,221,34) returns 0. Happens if a click strayed (e.g. opened another panel, dismissed the field), the capture is mid-transition, or OCR regressed.

Common situations: A fine-tune click hit a different UI element and closed/changed the craft panel; the 200ms post-click delay is too short for the number to re-render; resolution drift moved the field off the crop.

Related errors


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