babalae/better-genshin-impact · error · Exception

未找到主词条对应的行: {mainAffixText}

Error message

未找到主词条对应的行:
{mainAffixText}

What it means

Thrown in GetArtifactStat when SingleOrDefault over mainAffixLines finds no line matching any localized main-affix name in artifactAffixStrDic (HP/ATK/DEF/CRIT/etc.). The OCR'd main-affix region did not contain a recognized affix-type label, so the artifact's main stat type cannot be determined.

Source

Thrown at BetterGenshinImpact/GameTask/AutoArtifactSalvage/AutoArtifactSalvageTask.cs:575

        (string Text, Rect Rect)[] levelAndMinorAffixResult = levelAndMinorAffixOcrResult.Regions.Where(r => r.Score > 0.5)
            .Where(r => r.Rect.BoundingRect().Left < levelAndMinorAffixRoi.Width * 0.1) // 一定是贴着左边的,排除套装效果文字也存在类似+15%的情况
            .OrderBy(r => r.Rect.Center.Y).ThenBy(r => r.Rect.Center.X).Select(r => (r.Text, r.Rect.BoundingRect())).ToArray();
        var levelAndMinorAffixLines = levelAndMinorAffixResult.Select(r => r.Text).ToArray();
        allText = string.Join('\n', new[]
        {
            nameOcrResult.Text,
            typeOcrResult.Text,
            mainAffixText
        }.Concat(levelAndMinorAffixLines));

        string percentStr = "%";

        // 名称
        string name = nameOcrResult.Text;

        #region 主词条
        var defaultMainAffix = this.artifactAffixStrDic.Select(kvp => kvp.Value).Distinct();
        string mainAffixTypeLine = mainAffixLines.SingleOrDefault(l => defaultMainAffix.Contains(l)) ?? throw new Exception($"未找到主词条对应的行:\n{mainAffixText}");
        ArtifactAffixType mainAffixType = this.artifactAffixStrDic.First(kvp => kvp.Value == mainAffixTypeLine).Key;
        string mainAffixValueLine = mainAffixLines.Select(l =>
        {
            string pattern = @"^([\d., ]*)(%?)$";
            pattern = pattern.Replace("%", percentStr);   // 这样一行一行写只是为了IDE能保持正则字符串高亮
            Match match = Regex.Match(l, pattern);
            if (match.Success)
            {
                if (mainAffixType == ArtifactAffixType.ATK && !String.IsNullOrEmpty(match.Groups[2].Value))
                {
                    mainAffixType = ArtifactAffixType.ATKPercent;
                }
                if (mainAffixType == ArtifactAffixType.DEF && !String.IsNullOrEmpty(match.Groups[2].Value))
                {
                    mainAffixType = ArtifactAffixType.DEFPercent;
                }
                if (mainAffixType == ArtifactAffixType.HP && !String.IsNullOrEmpty(match.Groups[2].Value))
                {

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Verify the in-game language matches param.GameCultureInfo and the string localizer.
  2. Inspect allText (the out param) to see what OCR actually captured for the main affix.
  3. Confirm the card crop Rect percentages still match the current game UI layout.
  4. Lower the OCR Score filter or re-run preprocessing if text is faint.
Defensive patterns

Strategy: validation

Validate before calling

bool HasKnownMainAffix(IEnumerable<string> lines, FrozenDictionary<ArtifactAffixType,string> dic)
{
    var names = dic.Values.Distinct().ToHashSet();
    return lines.Any(l => names.Contains(l));
}

Try / catch

try { artifact = GetArtifactStat(card.SrcMat, ocr, out var text); }
catch (Exception e) { if (recognitionFailurePolicy == RecognitionFailurePolicy.Skip) continue; else throw; }

Prevention

When it happens

Trigger: OCR returned empty/garbled text for the main-affix region (Score<=0.5 filtered everything); game language or culture does not match artifactAffixStrDic translations; the artifact card crop rect is wrong so the affix name is outside the ROI; threshold/morph preprocessing destroyed the text.

Common situations: Wrong in-game language vs configured cultureInfo; UI scale/resolution changed shifting the card layout; OCR model weakness on stylized fonts; a promotional/non-standard artifact with an unexpected affix.

Related errors


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