babalae/better-genshin-impact · error · InvalidOperationException
最终合成个数与目标不一致,目标 {targetQuantity},当前 {verifiedQuantity}。
Error message
最终合成个数与目标不一致,目标 {targetQuantity},当前 {verifiedQuantity}。 What it means
Thrown at the end of SetCraftQuantity when the finally-read verifiedQuantity is parseable but not exactly equal to targetQuantity. After slider drag and deterministic add/reduce clicks the expected and actual counts must match exactly; any drift is treated as a failure.
Source
Thrown at BetterGenshinImpact/GameTask/Common/Job/CraftMaterialTask.cs:447
}
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);
}
/// <summary>
/// 读取当前材料最大可合成个数。
/// </summary>View on GitHub (pinned to a7cb36712d)
Solutions
- Drive the fine-tune loops by re-reading the quantity each iteration instead of incrementing a local counter, so a dropped click is self-correcting.
- Bound the loop iterations to avoid runaway clicks if a button is broken.
- If OCR misreads are suspected, re-read verifiedQuantity once more before comparing.
- Verify add/reduce button coordinates and click timing at the current scale.
Example fix
// before
while (actualQuantity < targetQuantity)
{
GameCaptureRegion.GameRegion1080PPosClick(addButton.X, addButton.Y);
await Delay(60, _ct);
actualQuantity++;
}
// after: re-read each iteration so a missed click self-corrects
int guard = 0;
while (actualQuantity < targetQuantity && guard++ < 200)
{
GameCaptureRegion.GameRegion1080PPosClick(addButton.X, addButton.Y);
await Delay(60, _ct);
var read = ReadCurrentCraftQuantity();
actualQuantity = read > 0 ? read : actualQuantity + 1;
} Defensive patterns
Strategy: retry
Validate before calling
null
Type guard
null
Try / catch
try { await SetCraftQuantity(target); }
catch (InvalidOperationException e) when (e.Message.Contains("最终合成个数与目标不一致"))
{ /* read again; if OCR jitter, accept within a small tolerance or redo fine-tune */ } Prevention
- Drive fine-tune loops by re-reading the quantity each click instead of a local counter.
- Bound fine-tune iterations to avoid runaway clicks.
- Re-read verifiedQuantity once more before the exact-equality compare to absorb OCR jitter.
When it happens
Trigger: verifiedQuantity (from ReadCurrentCraftQuantity) is a valid positive int but differs from targetQuantity. Caused by a fine-tune click not registering (loop overshot/undershot by counting a click that didn't land), or by the quantity changing asynchronously.
Common situations: An add/reduce click was dropped due to input lag, so the loop's bookkeeping (actualQuantity++/--) diverged from the UI; the slider auto-snapped to a different value after the loops; OCR misread one digit so verifiedQuantity is off by 10/100.
Related errors
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/93373309a299843b.
Report an issue: GitHub.