babalae/better-genshin-impact · critical · FileNotFoundException
模板素材未找到
Error message
模板素材未找到
What it means
Thrown as a FileNotFoundException by LoadTemplate when a template image file (e.g. Assets/icon/open.png, Assets/icon/close.png) referenced by a RecognitionObject does not exist on disk. LoadTemplate resolves the path under GameTask/AutoLeyLineOutcrop and is called during LoadRecognitionObjects to build template-matching ROIs for icons like the ley line open/close buttons, box icon, map settings button, and handbook track-action button.
Source
Thrown at BetterGenshinImpact/GameTask/AutoLeyLineOutcrop/AutoLeyLineOutcropTask.cs:280
{
ro.RegionOfInterest = roi.Value;
}
return ro;
}
private Mat LoadTemplate(string relativePath)
{
if (_templateCache.TryGetValue(relativePath, out var cached))
{
return cached;
}
var workDir = Global.Absolute(@"GameTask\AutoLeyLineOutcrop");
var fullPath = Path.Combine(workDir, relativePath.Replace("/", Path.DirectorySeparatorChar.ToString()));
if (!File.Exists(fullPath))
{
throw new FileNotFoundException("模板素材未找到", fullPath);
}
var mat = Mat.FromStream(File.OpenRead(fullPath), ImreadModes.Color);
// Resize once and reuse to avoid repeated scaling during recognition.
var scaled = ResizeHelper.Resize(mat, _systemInfo.AssetScale);
_templateCache[relativePath] = scaled;
return scaled;
}
private async Task<int> HandleResinExhaustionMode()
{
if (!_taskParam.IsResinExhaustionMode)
{
return _taskParam.Count;
}
var result = await CalCountByResin();
if (result.Count <= 0)View on GitHub (pinned to a7cb36712d)
Solutions
- Reinstall the application to restore all bundled icon assets.
- Verify the Assets/icon directory under GameTask/AutoLeyLineOutcrop contains all expected .png and .bmp files.
- If building from source, ensure image files have Build Action set to Content and CopyToOutputDirectory.
- Check the error message's fileName field to identify which specific template is missing.
Defensive patterns
Strategy: validation
Validate before calling
// Before building recognition objects, verify all template files exist
var workDir = Global.Absolute(@"GameTask\AutoLeyLineOutcrop");
var requiredTemplates = new[] { "Assets/icon/open.png", "Assets/icon/close.png", "Assets/icon/box.png" };
foreach (var rel in requiredTemplates)
{
var fullPath = Path.Combine(workDir, rel);
if (!File.Exists(fullPath))
{
Logger.LogError("模板素材缺失: {Path}", fullPath);
}
} Try / catch
catch (FileNotFoundException ex) when (ex.Message.Contains("模板素材未找到"))
{
logger.LogError("模板图片缺失: {Path}", ex.FileName);
ThemedMessageBox.Error($"模板图片缺失,请重新安装程序: {ex.FileName}", "文件未找到");
} Prevention
- Use a complete application installation with all icon assets.
- If building from source, verify image files have Build Action = Content and CopyToOutputDirectory.
- Do not delete or move files under the Assets/icon directory.
When it happens
Trigger: LoadTemplate is called for each template path during Initialize. Fires when any one of the expected image files (open.png, close.png, paimon_menu.png, box.png, map_setting_button.bmp, handbook_track_action_left.png) is missing from the Assets/icon directory.
Common situations: Incomplete installation missing icon assets; antivirus quarantine; the image file was renamed or moved during a refactor; a build did not copy image resources to the output; a version update added a new template but the old installation was not fully replaced.
Related errors
- config.json 未找到
- LeyLineOutcropData.json 未找到
- 未找到{taskName}的素材文件夹
- 未找到{taskName}中的{assetName}文件
- config.json 解析失败
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/cdcc7c69a5b1b6df.
Report an issue: GitHub.