babalae/better-genshin-impact · error · InvalidOperationException

未找到原粹树脂图标

Error message

未找到原粹树脂图标

What it means

Thrown by AutoBossTask.RecognizeOriginalResinInfoFromBigMap when the template match for 'OriginalResinTopIcon' returns an empty region inside the cropped search area ScaleRect(1200,25,580,50). The resin icon must be visible in the top-right of the big-map UI for AutoBoss to compute remaining resin from recovery time.

Source

Thrown at BetterGenshinImpact/GameTask/AutoBoss/AutoBossTask.cs:313

    /// 释放输入并打开大地图界面,用于在右上角读取原粹树脂数量。
    /// </summary>
    private async Task OpenBigMapForResinCheck()
    {
        await new TpTask(_ct).OpenBigMapUi();
    }

    /// <summary>
    /// AutoBoss 专用大地图原粹树脂识别:点击右上角树脂图标后,通过全部恢复时间反推剩余树脂。
    /// </summary>
    /// <returns>当前剩余原粹树脂。</returns>
    private async Task<OriginalResinInfo> RecognizeOriginalResinInfoFromBigMap()
    {
        using var capture = CaptureToRectArea();
        using var resinIconSearchRegion = capture.DeriveCrop(ScaleRect(1200, 25, 580, 50));
        var resinIconRegion = resinIconSearchRegion.Find(LoadRecognitionObject("OriginalResinTopIcon"));
        if (resinIconRegion.IsEmpty())
        {
            throw new InvalidOperationException("未找到原粹树脂图标");
        }

        var iconLeft = resinIconSearchRegion.X + resinIconRegion.Left;
        var iconRight = resinIconSearchRegion.X + resinIconRegion.Right;
        var iconBottom = resinIconSearchRegion.Y + resinIconRegion.Bottom;

        resinIconRegion.Click();
        await Delay(500, _ct);

        using var clickedCapture = CaptureToRectArea();
        var resinLimit = RecognizeOriginalResinLimit(clickedCapture, iconRight);
        var fullRecoveryTime = RecognizeFullRecoveryTime(clickedCapture, iconLeft, iconBottom);
        var missingResin = (int)Math.Ceiling(fullRecoveryTime.TotalSeconds / OriginalResinRecoveryInterval.TotalSeconds);
        if (missingResin > resinLimit)
        {
            throw new InvalidOperationException($"计算缺失树脂 {missingResin} 超过树脂上限 {resinLimit}");
        }

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Confirm the big-map UI is fully loaded before calling (increase Delay after OpenBigMapUi).
  2. Verify the game resolution matches ScaleRect assumptions; adjust or scale the search rect by AssetScale.
  3. Update the 'OriginalResinTopIcon' template asset to match the current game art.
  4. Retry the capture once before failing, since UI animations can momentarily hide the icon.

Example fix

// before
using var capture = CaptureToRectArea();
using var resinIconSearchRegion = capture.DeriveCrop(ScaleRect(1200, 25, 580, 50));
var resinIconRegion = resinIconSearchRegion.Find(LoadRecognitionObject("OriginalResinTopIcon"));
if (resinIconRegion.IsEmpty()) throw new InvalidOperationException("未找到原粹树脂图标");
// after - scale rect + one retry
var searchRect = ScaleRect(1200, 25, 580, 50);
Region resinIconRegion;
using (var capture = CaptureToRectArea())
using (var region = capture.DeriveCrop(searchRect))
{
    resinIconRegion = region.Find(LoadRecognitionObject("OriginalResinTopIcon"));
    if (resinIconRegion.IsEmpty()) { await Delay(500, _ct); /* re-capture and retry once */ }
}
Defensive patterns

Strategy: retry

Validate before calling

static bool IsResinIconLikelyVisible(ImageRegion capture)
{
    using var roi = capture.DeriveCrop(ScaleRect(1200, 25, 580, 50));
    return roi.Find(LoadRecognitionObject("OriginalResinTopIcon")).IsExist();
}

Try / catch

for (int i = 0; i < 2; i++)
{
    try { return await RecognizeOriginalResinInfoFromBigMap(); }
    catch (InvalidOperationException ex) when (ex.Message.Contains("原粹树脂图标") && i == 0)
    { await Delay(500, _ct); }
}

Prevention

When it happens

Trigger: The big-map UI is not actually open (OpenBigMapUi failed silently); the icon's screen position shifted due to resolution/scale mismatch with the hardcoded 1200,25,580,50 rect; the template image is stale (game updated the icon art); the crop region is off-screen at the current resolution.

Common situations: Game resolution or UI scale changed so the hardcoded crop no longer covers the icon; game patched the resin icon art; the map did not open in time (race before the capture); the asset template missing from the resources.

Related errors


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