babalae/better-genshin-impact · error · InvalidOperationException

滑块调整合成个数后校验失败,目标 {targetQuantity},当前 {actualQuantity}。

Error message

滑块调整合成个数后校验失败,目标 {targetQuantity},当前 {actualQuantity}。

What it means

Thrown when, after dragging the slider and one retry drag, the recognized current quantity is still more than 30 away from the target. It indicates the slider-to-quantity mapping is imprecise at this target ratio and the fine-adjustment buttons have not yet been engaged.

Source

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

        var ratio = Math.Clamp((targetQuantity - 1d) / (maxQuantity - 1d), 0d, 1d);
        await DragSliderToRatio(ratio);
        await Delay(350, _ct);

        var actualQuantity = ReadCurrentCraftQuantity();
        if (actualQuantity <= 0)
        {
            throw new InvalidOperationException("未能读取当前合成个数。");
        }

        if (Math.Abs(actualQuantity - targetQuantity) > 30)
        {
            await DragSliderToRatio(ratio);
            await Delay(350, _ct);
            actualQuantity = ReadCurrentCraftQuantity();
            if (actualQuantity <= 0 || Math.Abs(actualQuantity - targetQuantity) > 30)
            {
                throw new InvalidOperationException($"滑块调整合成个数后校验失败,目标 {targetQuantity},当前 {actualQuantity}。");
            }
        }

        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);

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Improve the ratio->quantity model: drag, read, then compute a corrected ratio from the error instead of repeating the identical drag.
  2. Verify the slider grab point (sliderStartX 1173, Y 672) actually contacts the handle at the current scale.
  3. Widen the tolerance band before switching to fine add/reduce clicks, since the subsequent while-loops correct small offsets deterministically.
  4. Log ratio, targetQuantity, and actualQuantity each attempt to calibrate the non-linear curve.

Example fix

// before
await DragSliderToRatio(ratio);
await Delay(350, _ct);
actualQuantity = ReadCurrentCraftQuantity();
if (actualQuantity <= 0 || Math.Abs(actualQuantity - targetQuantity) > 30)
{
    throw new InvalidOperationException($"滑块调整合成个数后校验失败,目标 {targetQuantity},当前 {actualQuantity}。");
}

// after: correct ratio from observed error before giving up
if (Math.Abs(actualQuantity - targetQuantity) > 30 && maxQuantity > 1)
{
    var corrected = Math.Clamp(ratio + (targetQuantity - actualQuantity) / (double)(maxQuantity - 1), 0d, 1d);
    await DragSliderToRatio(corrected);
    await Delay(350, _ct);
    actualQuantity = ReadCurrentCraftQuantity();
}
if (actualQuantity <= 0 || Math.Abs(actualQuantity - targetQuantity) > 30)
{
    throw new InvalidOperationException($"滑块调整合成个数后校验失败,目标 {targetQuantity},当前 {actualQuantity}。");
}
Defensive patterns

Strategy: retry

Validate before calling

null

Type guard

null

Try / catch

try { await SetCraftQuantity(target); }
catch (InvalidOperationException e) when (e.Message.Contains("滑块调整合成个数后校验失败"))
{ /* fall back to pure fine-tune clicks from min/max instead of slider ratio */ }

Prevention

When it happens

Trigger: targetQuantity is mid-range, DragSliderToRatio lands the handle off by many units (slider geometry non-linear), and a second identical drag does not converge. Concretely Math.Abs(actualQuantity - targetQuantity) > 30 holds on both the first and the retry read.

Common situations: The game slider's pixel-to-quantity curve is non-linear so the linear ratio interpolation overshoots; DPI/scale mismatch makes the dragged distance wrong; the slider handle was not grabbed (click landed beside it) so the ratio never changed.

Related errors


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