{"record":{"id":"93373309a299843b","repo":"babalae/better-genshin-impact","slug":"targetquantity-verifiedquant","errorCode":null,"errorMessage":"最终合成个数与目标不一致，目标 {targetQuantity}，当前 {verifiedQuantity}。","messagePattern":"最终合成个数与目标不一致，目标 (.+?)，当前 (.+?)。","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/GameTask/Common/Job/CraftMaterialTask.cs","lineNumber":447,"sourceCode":"        }\n\n        while (actualQuantity > targetQuantity)\n        {\n            GameCaptureRegion.GameRegion1080PPosClick(reduceButton.X, reduceButton.Y);\n            await Delay(60, _ct);\n            actualQuantity--;\n        }\n\n        await Delay(200, _ct);\n        var verifiedQuantity = ReadCurrentCraftQuantity();\n        if (verifiedQuantity <= 0)\n        {\n            throw new InvalidOperationException(\"最终合成个数读取失败。\");\n        }\n\n        if (verifiedQuantity != targetQuantity)\n        {\n            throw new InvalidOperationException($\"最终合成个数与目标不一致，目标 {targetQuantity}，当前 {verifiedQuantity}。\");\n        }\n\n        return verifiedQuantity;\n    }\n\n    /// <summary>\n    /// 读取右侧当前合成个数。\n    /// </summary>\n    /// <returns>识别到的当前合成个数；失败时返回 0。</returns>\n    private int ReadCurrentCraftQuantity()\n    {\n        var text = StringUtils.ConvertFullWidthNumToHalfWidth(ReadOcrText(Rect1080(1248, 615, 221, 34)));\n        return ReadFirstPositiveInt(text);\n    }\n\n    /// <summary>\n    /// 读取当前材料最大可合成个数。\n    /// </summary>","sourceCodeStart":429,"sourceCodeEnd":465,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/GameTask/Common/Job/CraftMaterialTask.cs#L429-L465","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nwhile (actualQuantity < targetQuantity)\n{\n    GameCaptureRegion.GameRegion1080PPosClick(addButton.X, addButton.Y);\n    await Delay(60, _ct);\n    actualQuantity++;\n}\n\n// after: re-read each iteration so a missed click self-corrects\nint guard = 0;\nwhile (actualQuantity < targetQuantity && guard++ < 200)\n{\n    GameCaptureRegion.GameRegion1080PPosClick(addButton.X, addButton.Y);\n    await Delay(60, _ct);\n    var read = ReadCurrentCraftQuantity();\n    actualQuantity = read > 0 ? read : actualQuantity + 1;\n}","handlingStrategy":"retry","validationCode":"null","typeGuard":"null","tryCatchPattern":"try { await SetCraftQuantity(target); }\ncatch (InvalidOperationException e) when (e.Message.Contains(\"最终合成个数与目标不一致\"))\n{ /* read again; if OCR jitter, accept within a small tolerance or redo fine-tune */ }","preventionTips":["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."],"tags":["ocr","crafting","verification","input-simulation"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}