babalae/better-genshin-impact · warning · NotSupportedException
不被 Locator 支持的识别类型: {RecognitionObject.RecognitionType}
Error message
不被 Locator 支持的识别类型: {RecognitionObject.RecognitionType} What it means
Thrown by ValidatePixelCount when the decoded image has non-positive dimensions or when width * height exceeds MaxPixelCount (40,000,000 pixels). This is a safety guard against decompression-bomb attacks and excessive memory usage from large images. The check uses a long cast to avoid integer overflow in the multiplication.
Source
Thrown at BetterGenshinImpact/Core/BgiVision/BvLocator.cs:89
{
if (RecognitionObject.RecognitionType == RecognitionTypes.TemplateMatch)
{
var region = screen.Find(RecognitionObject);
if (region.IsExist())
{
return [region];
}
return [];
}
else if (RecognitionObject.RecognitionType == RecognitionTypes.Ocr)
{
var results = screen.FindMulti(RecognitionObject);
return FilterOcrResults(results, _anyTexts, RecognitionObject.Text);
}
else
{
throw new NotSupportedException($"不被 Locator 支持的识别类型: {RecognitionObject.RecognitionType}");
}
}
internal static List<Region> FilterOcrResults(
List<Region> results,
IReadOnlyList<string> anyTexts,
string text)
{
if (anyTexts.Count > 0)
{
return results.FindAll(region =>
anyTexts.Any(candidate => region.Text.Contains(candidate, StringComparison.Ordinal)));
}
return string.IsNullOrEmpty(text)
? results
: results.FindAll(region => region.Text.Contains(text, StringComparison.Ordinal));
}View on GitHub (pinned to a7cb36712d)
Solutions
- Resize the image to under 40 million total pixels (e.g. max ~6300x6300) before referencing it.
- If the dimensions are bogus (corrupt header), re-export the image from its source.
- Increase MaxPixelCount if large images are a legitimate requirement (recompile).
Example fix
// before
if (width <= 0 || height <= 0 || (long)width * height > MaxPixelCount)
throw new InvalidDataException("图片像素尺寸无效或超过安全限制。");
// after — downscale large images instead of rejecting
if (width <= 0 || height <= 0)
throw new InvalidDataException("图片尺寸无效。");
if ((long)width * height > MaxPixelCount)
{
var scale = Math.Sqrt((double)MaxPixelCount / (width * height));
// apply downscale via TransformedBitmap before returning
} Defensive patterns
Strategy: validation
Validate before calling
// Pre-check dimensions after decode, before creating BitmapSource ValidatePixelCount(image.Width, image.Height); // Or downscale if over limit
Type guard
static bool IsPixelCountSafe(int w, int h) =>
w > 0 && h > 0 && (long)w * h <= MaxPixelCount; Try / catch
try { ValidatePixelCount(width, height); }
catch (InvalidDataException) { /* downscale or return placeholder */ } Prevention
- Resize images to under 40M pixels before embedding in Markdown.
- Implement automatic downscaling for oversized images.
- Use the long-cast multiplication to avoid integer overflow in dimension checks.
When it happens
Trigger: ValidatePixelCount(width, height) is called after decoding; triggers when width <= 0, height <= 0, or (long)width * height > 40_000_000. Happens with very high-resolution images (e.g. 8000x6000 = 48M pixels) or corrupted metadata reporting absurd dimensions.
Common situations: Markdown references a very large wallpaper or screenshot, a malformed image header reports fake huge dimensions, or a legitimate large diagram exceeds the conservative 40M-pixel limit.
Related errors
- 等待 {targetDescription} 超时({timeout}ms)
- 添加流程步骤后不能修改流程默认配置
- 没有可用的上一步识别位置,无法执行隐式坐标操作
- milliseconds 不能小于 0
- 一次性动作不支持 WithTimeout 或 WithRetryInterval,请使用 Until 系列方法设置重试条
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/4196c5a64ad52b90.
Report an issue: GitHub.