babalae/better-genshin-impact · error · Exception

尝试获取生之花失败

Error message

尝试获取生之花失败

What it means

Thrown by GetGridIconsTask.GetArtifactSetFilterGridIcons after two failed attempts to OCR-recognize the flower (生之花) name from the artifact set filter screen. The local function tryGetFlower returns false when the OCR result does not contain a '套装包含' (set contains) region. After scrolling and retrying, a second failure aborts with a generic Exception.

Source

Thrown at BetterGenshinImpact/GameTask/GetGridIcons/GetGridIconsTask.cs:200

                var whiteOcrResult = OcrFactory.Paddle.OcrResult(roi);
                flowerName = whiteOcrResult.Text;
                // 所以只好识别两次,Trim后根据字数取原截图OCR的结果……
                flowerName = flowerWithGlyph.Text.Trim().Substring(flowerWithGlyph.Text.Trim().Length - flowerName.Trim().Length);
                return true;
            }

            if (!tryGetFlower(out string flowerName))
            {
                await TaskControl.Delay(100, this.ct);
                for (int i = 0; i < 5; i++)
                {
                    this.input.Mouse.VerticalScroll(-2);
                    await TaskControl.Delay(40, this.ct);
                }
                await TaskControl.Delay(300, this.ct);
                if (!tryGetFlower(out flowerName))
                {
                    throw new Exception("尝试获取生之花失败");
                    //flowerName = $"识别失败{nameRegion.GetHashCode()}";
                }
            }

            string fileName = flowerName;
            if (fileNames.Add(fileName))
            {
                string filePath = Path.Combine(directory, $"{fileName}.png");
                Thread saveThread = new Thread(() =>
                {
                    try
                    {
                        using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None))
                        {
                            using Mat img125 = CropResizeArtifactSetFilterGridIcon(itemRegion);
                            img125.ToBitmap().Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                        }
                        logger.LogInformation("图片保存成功:{Text}", fileName);

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Ensure the game language is set to Chinese (simplified) so the '套装包含' OCR trigger text is present.
  2. Manually open the artifact set filter detail panel before starting the task, as indicated by the log message for unsupported auto-open.
  3. Verify the game window is fully visible and not occluded.
  4. Check that the game resolution is 1920x1080 or the crop region proportions still match.
  5. Consider catching this exception and skipping the item with a fallback name instead of aborting the entire task.

Example fix

// before
if (!tryGetFlower(out flowerName))
{
    throw new Exception("尝试获取生之花失败");
}

// after — degrade gracefully instead of aborting
if (!tryGetFlower(out flowerName))
{
    flowerName = $"识别失败_{DateTime.Now:HHmmss}";
    logger.LogWarning("尝试获取生之花失败,使用回退名称:{Name}", flowerName);
}
Defensive patterns

Strategy: try-catch

Try / catch

try { await GetArtifactSetFilterGridIcons(count, directory); }
catch (Exception ex) when (ex.Message.Contains("生之花"))
{ logger.LogWarning(ex, "OCR 识别生之花失败,跳过该项"); }

Prevention

When it happens

Trigger: Calling GetArtifactSetFilterGridIcons when the game UI does not show the expected artifact set filter detail panel, OCR fails to detect the '套装包含' text, or the flower name region is obscured/blank. The error fires only after the retry with scrolling also fails.

Common situations: The game language is not Chinese so the OCR text pattern does not match; the game window is partially occluded or the detail panel did not open; the game UI changed in a version update shifting the OCR crop region; running on a resolution where the crop proportions are off.

Related errors


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